Skip to content

Commit 9a27204

Browse files
committed
feat: Add explicit encode and decode email commands, validate when issue opened
1 parent d46d9f2 commit 9a27204

File tree

4 files changed

+280
-63
lines changed

4 files changed

+280
-63
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Encode or decode string"
2+
description: "Encode or decode string"
3+
inputs:
4+
input_string:
5+
description: "String to encode or decode"
6+
required: true
7+
encryption_key:
8+
description: "Encryption key used for encoding or decoding"
9+
required: true
10+
operation:
11+
description: Operation to perform 'decode' or 'encode'
12+
required: true
13+
skip:
14+
description: Whether to skip the selected operation.
15+
default: "false"
16+
outputs:
17+
output_string:
18+
description:
19+
"Encoded or decoded string. If skip is true, set to input string."
20+
value: ${{ steps.encode_decode.outputs.output_string }}
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: "Encode or decode string"
25+
id: encode_decode
26+
shell: bash
27+
run: |
28+
if [[ ! $SKIP =~ ^(false|true)$ ]]; then
29+
echo "::error ::Invalid skip value '$SKIP'. Supported values are 'true' or 'false'"
30+
exit 1
31+
fi
32+
if [[ ! $OPERATION =~ ^(encode|decode)$ ]]; then
33+
echo "::error ::Invalid operation value '$OPERATION'. Supported values are 'encode' or 'decode'"
34+
exit 1
35+
fi
36+
if [[ $SKIP == "false" ]]; then
37+
if [[ $OPERATION == "encode" ]]; then
38+
output_string=$(echo "$INPUT_STRING" | openssl enc -base64 -e -aes-256-cbc -salt -pass pass:$ENCRYPTION_KEY -pbkdf2)
39+
else
40+
output_string=$(echo "$INPUT_STRING" | openssl enc -base64 -d -aes-256-cbc -salt -pass pass:$ENCRYPTION_KEY -pbkdf2)
41+
fi
42+
else
43+
output_string=$INPUT_STRING
44+
fi
45+
echo "output_string=$output_string" >> $GITHUB_OUTPUT
46+
env:
47+
INPUT_STRING: ${{ inputs.input_string }}
48+
ENCRYPTION_KEY: ${{ inputs.encryption_key }}
49+
OPERATION: ${{ inputs.operation }}
50+
SKIP: ${{ fromJSON(inputs.skip) }}

.github/workflows/update-issue.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Update Issue
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
# Permissions needed for reacting to IssueOps commands on issues
8+
permissions:
9+
issues: write
10+
checks: read
11+
12+
jobs:
13+
update-issue:
14+
runs-on: ubuntu-latest
15+
if:
16+
${{ !github.event.issue.pull_request && (
17+
contains(github.event.comment.body, '/encode_email') ||
18+
contains(github.event.comment.body, '/decode_email') ) }}
19+
steps:
20+
- name: encode_email command
21+
id: encode_email_command
22+
uses: github/[email protected]
23+
with:
24+
command: "/encode_email"
25+
reaction: "rocket"
26+
allowed_contexts: "issue"
27+
permissions: "read,triage,write,maintain,admin"
28+
allowlist: "jcfr,muratmaga,${{ github.event.issue.user.login }}"
29+
30+
- name: decode_email command
31+
id: decode_email_command
32+
uses: github/[email protected]
33+
with:
34+
command: "/decode_email"
35+
reaction: "rocket"
36+
allowed_contexts: "issue"
37+
permissions: "read,triage,write,maintain,admin"
38+
allowlist: "jcfr,muratmaga,${{ github.event.issue.user.login }}"
39+
40+
- name: Set command metadata
41+
id: command
42+
if:
43+
${{ steps.encode_email_command.outputs.continue == 'true' ||
44+
steps.decode_email_command.outputs.continue == 'true' }}
45+
run: |
46+
if [[ "$ENCODE_EMAIL_COMMAND_CONTINUE" == "true" ]]; then
47+
continue="$ENCODE_EMAIL_COMMAND_CONTINUE"
48+
command_name="encode_email"
49+
comment_id="${{ steps.encode_email_command.outputs.comment_id }}"
50+
elif [[ "$DECODE_EMAIL_COMMAND_CONTINUE" == "true" ]]; then
51+
continue="$DECODE_EMAIL_COMMAND_CONTINUE"
52+
command_name="decode_email"
53+
comment_id="${{ steps.decode_email_command.outputs.comment_id }}"
54+
else
55+
continue="false"
56+
command_name=""
57+
comment_id=""
58+
fi
59+
echo "continue=$continue" >> $GITHUB_OUTPUT
60+
echo "command_name=$command_name" >> $GITHUB_OUTPUT
61+
echo "comment_id=$comment_id" >> $GITHUB_OUTPUT
62+
env:
63+
ENCODE_EMAIL_COMMAND_CONTINUE:
64+
${{ steps.encode_email_command.outputs.continue }}
65+
DECODE_EMAIL_COMMAND_CONTINUE:
66+
${{ steps.decode_email_command.outputs.continue }}
67+
68+
- uses: actions/checkout@v4
69+
70+
- name: Extract fields
71+
id: extract
72+
uses: ./.github/actions/extract-issue-fields
73+
with:
74+
token: ${{ secrets.GITHUB_TOKEN }}
75+
repository: ${{ github.repository }}
76+
issue_number: ${{ github.event.issue.number }}
77+
78+
- name: Check if email is encoded
79+
id: check_email_encryption
80+
run: |
81+
if [[ "$EMAIL" != *"@"* ]]; then
82+
encoded="true"
83+
else
84+
encoded="false"
85+
fi
86+
echo "encoded=$encoded" >> $GITHUB_OUTPUT
87+
env:
88+
EMAIL: ${{ steps.extract.outputs.email }}
89+
90+
- name: Encode email
91+
id: encode_email
92+
if: ${{ steps.encode_email_command.outputs.continue == 'true' }}
93+
uses: ./.github/actions/encode-decode-string
94+
with:
95+
input_string: ${{ steps.extract.outputs.email }}
96+
encryption_key: ${{ secrets.STRING_ENCRYPTION_KEY }}
97+
operation: "encode"
98+
skip: ${{ steps.check_email_encryption.outputs.encoded == 'true' }}
99+
100+
- name: Decode email
101+
id: decode_email
102+
if: ${{ steps.decode_email_command.outputs.continue == 'true' }}
103+
uses: ./.github/actions/encode-decode-string
104+
with:
105+
input_string: ${{ steps.extract.outputs.email }}
106+
encryption_key: ${{ secrets.STRING_ENCRYPTION_KEY }}
107+
operation: "decode"
108+
skip: ${{ steps.check_email_encryption.outputs.encoded == 'false' }}
109+
110+
- name: Set updated email
111+
id: set_updated_email
112+
if: ${{ steps.command.outputs.continue == 'true' }}
113+
run: |
114+
updated_email=""
115+
if [[ "$ENCODE_EMAIL_COMMAND_CONTINUE" == "true" ]]; then
116+
updated_email="$ENCODED_EMAIL"
117+
elif [[ "$DECODE_EMAIL_COMMAND_CONTINUE" == "true" ]]; then
118+
updated_email="$DECODED_EMAIL"
119+
fi
120+
echo "updated_email=$updated_email" >> $GITHUB_OUTPUT
121+
env:
122+
ENCODE_EMAIL_COMMAND_CONTINUE:
123+
${{ steps.encode_email_command.outputs.continue }}
124+
ENCODED_EMAIL: ${{ steps.encode_email.outputs.output_string }}
125+
DECODE_EMAIL_COMMAND_CONTINUE:
126+
${{ steps.decode_email_command.outputs.continue }}
127+
DECODED_EMAIL: ${{ steps.decode_email.outputs.output_string }}
128+
129+
- name: Update issue body
130+
id: update_issue_body
131+
if: ${{ steps.command.outputs.continue == 'true' }}
132+
shell: bash
133+
run: |
134+
gh issue view $ISSUE_NUMBER \
135+
--repo $GH_REPO \
136+
--json body \
137+
--jq .body > ./body.md
138+
139+
# Replace email
140+
sed "s#$OLD_EMAIL#$NEW_EMAIL#" ./body.md > ./updated_body.md
141+
142+
gh issue edit $ISSUE_NUMBER \
143+
--repo $GH_REPO \
144+
--body-file ./updated_body.md
145+
env:
146+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147+
GH_REPO: ${{ github.repository }}
148+
ISSUE_NUMBER: ${{ github.event.issue.number }}
149+
OLD_EMAIL: ${{ steps.extract.outputs.email }}
150+
NEW_EMAIL: ${{ steps.set_updated_email.outputs.updated_email }}
151+
152+
- name: command results comment (success)
153+
if: ${{ steps.command.outputs.continue == 'true' && success() }}
154+
uses: peter-evans/[email protected]
155+
with:
156+
issue-number: ${{ github.event.issue.number }}
157+
body: |
158+
### Command Results ✅
159+
160+
`${{ steps.command.outputs.command_name }}` command successfully applied to this issue.
161+
162+
- name: command results comment (failure)
163+
if: ${{ steps.command.outputs.continue == 'true' && failure() }}
164+
uses: peter-evans/[email protected]
165+
with:
166+
issue-number: ${{ github.event.issue.number }}
167+
body: |
168+
### Command Results ❌
169+
170+
`${{ steps.command.outputs.command_name }}` command failed to be applied to this issue.
171+
172+
See details at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

.github/workflows/validate-request.yml

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
name: Validate Request
22

33
on:
4-
issue_comment:
5-
types: [created]
4+
issues:
5+
types:
6+
- opened
7+
workflow_dispatch:
8+
inputs:
9+
issue_number:
10+
description: "Issue number"
11+
required: true
612

713
# Permissions needed for reacting to IssueOps commands on issues
814
permissions:
915
issues: write
1016
checks: read
1117

1218
jobs:
13-
control:
19+
validate:
1420
runs-on: ubuntu-latest
15-
if:
16-
${{ !github.event.issue.pull_request && (
17-
contains(github.event.comment.body, '/validate') ) }}
1821
steps:
19-
- name: validate command
20-
id: validate_command
21-
uses: github/[email protected]
22-
with:
23-
command: "/validate"
24-
reaction: "rocket"
25-
allowed_contexts: "issue"
26-
permissions: "read,triage,write,maintain,admin"
27-
allowlist: "jcfr,muratmaga,${{ github.event.issue.user.login }}"
22+
- name: Collect Inputs
23+
id: collect_inputs
24+
run: |
25+
echo "EVENT_NAME [$EVENT_NAME]"
26+
if [[ "$EVENT_NAME" == "issues" ]]; then
27+
issue_number=${{ github.event.issue.number }}
28+
elif [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
29+
issue_number=${{ github.event.inputs.issue_number }}
30+
else
31+
echo "::error ::Unsupported EVENT_NAME [$EVENT_NAME]"
32+
exit 1
33+
fi
34+
echo "issue_number=$issue_number" >> $GITHUB_OUTPUT
35+
env:
36+
EVENT_NAME: ${{ github.event_name }}
2837

2938
- uses: actions/checkout@v4
3039

@@ -34,7 +43,7 @@ jobs:
3443
with:
3544
token: ${{ secrets.GITHUB_TOKEN }}
3645
repository: ${{ github.repository }}
37-
issue_number: ${{ github.event.issue.number }}
46+
issue_number: ${{ steps.collect_inputs.outputs.issue_number }}
3847

3948
- name: Check ORCID iD format
4049
id: check_orcid_format
@@ -51,65 +60,49 @@ jobs:
5160
env:
5261
ORCID: ${{ steps.extract.outputs.orcid }}
5362

54-
- name: Check email format
55-
id: check_email_format
63+
- name: Check if email is encoded
64+
id: check_email_encryption
5665
run: |
57-
input_email=$EMAIL
58-
if [[ "$input_email" != *"@"* ]]; then
59-
# decrypt
60-
email=$(echo "$input_email" | openssl enc -base64 -d -aes-256-cbc -salt -pass pass:$STRING_ENCRYPTION_KEY -pbkdf2)
66+
if [[ "$EMAIL" != *"@"* ]]; then
67+
encoded="true"
6168
else
62-
email=$input_email
69+
encoded="false"
6370
fi
71+
echo "encoded=$encoded" >> $GITHUB_OUTPUT
72+
env:
73+
EMAIL: ${{ steps.extract.outputs.email }}
74+
75+
- name: Decode email
76+
id: decode_email
77+
uses: ./.github/actions/encode-decode-string
78+
with:
79+
input_string: ${{ steps.extract.outputs.email }}
80+
encryption_key: ${{ secrets.STRING_ENCRYPTION_KEY }}
81+
operation: "decode"
82+
skip: ${{ steps.check_email_encryption.outputs.encoded == 'false' }}
6483

84+
- name: Check email format
85+
id: check_email_format
86+
run: |
6587
# Adapted from https://gist.github.com/guessi/82a73ee7eb2b1216eb9db17bb8d65dd1
6688
email_regex="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
67-
if [[ "$email" =~ $email_regex ]]; then
89+
if [[ "$EMAIL" =~ $email_regex ]]; then
6890
valid="true"
6991
emojii="✅"
7092
else
7193
valid="false"
7294
emojii="❌"
7395
fi
74-
75-
encrypted_email=$(echo "$email" | openssl enc -base64 -e -aes-256-cbc -salt -pass pass:$STRING_ENCRYPTION_KEY -pbkdf2)
76-
7796
echo "valid=$valid" >> $GITHUB_OUTPUT
7897
echo "emojii=$emojii" >> $GITHUB_OUTPUT
79-
echo "email=$email" >> $GITHUB_OUTPUT
80-
echo "encrypted_email=$encrypted_email" >> $GITHUB_OUTPUT
81-
env:
82-
EMAIL: ${{ steps.extract.outputs.email }}
83-
STRING_ENCRYPTION_KEY: ${{ secrets.STRING_ENCRYPTION_KEY }}
84-
85-
- name: Update issue body
86-
id: update_issue_body
87-
shell: bash
88-
run: |
89-
body=$(gh issue view $ISSUE_NUMBER \
90-
--repo $GH_REPO \
91-
--json body | \
92-
jq '.body')
93-
94-
# Replace email
95-
updated_body=$(echo "$body" | sed "s#$EMAIL#$ENCRYPTED_EMAIL#")
96-
97-
gh issue edit $ISSUE_NUMBER \
98-
--repo $GH_REPO \
99-
--body "${updated_body}"
10098
env:
101-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102-
GH_REPO: ${{ github.repository }}
103-
ISSUE_NUMBER: ${{ github.event.issue.number }}
104-
EMAIL: ${{ steps.check_email_format.outputs.email }}
105-
ENCRYPTED_EMAIL:
106-
${{ steps.check_email_format.outputs.encrypted_email }}
99+
EMAIL: ${{ steps.decode_email.outputs.output_string }}
107100

108101
- name: command results comment (failure)
109102
if: ${{ failure() }}
110103
uses: peter-evans/[email protected]
111104
with:
112-
issue-number: ${{ github.event.issue.number }}
105+
issue-number: ${{ steps.collect_inputs.outputs.issue_number }}
113106
body: |
114107
### Command Results ❌
115108
@@ -120,7 +113,7 @@ jobs:
120113
if: ${{ success() }}
121114
uses: peter-evans/[email protected]
122115
with:
123-
issue-number: ${{ github.event.issue.number }}
116+
issue-number: ${{ steps.collect_inputs.outputs.issue_number }}
124117
body: |
125118
### Validation Results
126119

0 commit comments

Comments
 (0)