|
| 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 | + |
| 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 | + |
| 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 }} |
0 commit comments