|
| 1 | +name: Handle a PR comment |
| 2 | +run-name: Handle slash command in a PR comment` |
| 3 | + |
| 4 | +on: |
| 5 | + # GitGitGadget's GitHub App is expected to trigger this on `issue_comment` events |
| 6 | + # that have the `action` set to `created` or `edited` |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + pr-comment-url: |
| 10 | + description: 'URL of the PR comment to handle' |
| 11 | + required: true |
| 12 | + |
| 13 | +env: |
| 14 | + PR_COMMENT_URL: ${{ inputs.pr-comment-url }} |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ inputs.pr-comment-url }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + handle-pr-comment: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/create-github-app-token@v1 |
| 25 | + id: gitgitgadget-git-token |
| 26 | + with: |
| 27 | + app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }} |
| 28 | + private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }} |
| 29 | + owner: gitgitgadget |
| 30 | + repositories: git |
| 31 | + - uses: actions/create-github-app-token@v1 |
| 32 | + id: git-git-token |
| 33 | + with: |
| 34 | + app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }} |
| 35 | + private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }} |
| 36 | + owner: git |
| 37 | + repositories: git |
| 38 | + - uses: actions/create-github-app-token@v1 |
| 39 | + id: dscho-git-token |
| 40 | + with: |
| 41 | + app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }} |
| 42 | + private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }} |
| 43 | + owner: dscho |
| 44 | + repositories: git |
| 45 | + - name: create a check run |
| 46 | + id: create-check-run |
| 47 | + run: | |
| 48 | + title="Handle PR comment" |
| 49 | + summary="Handling PR comment $PR_COMMENT_URL" |
| 50 | + details_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 51 | + text="This handles $PR_COMMENT_URL, see $details_url for details." |
| 52 | + echo "title=$title" >> $GITHUB_OUTPUT |
| 53 | + echo "summary=$summary" >> $GITHUB_OUTPUT |
| 54 | + echo "text=$text" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + PR_NUMBER="${PR_COMMENT_URL%#*}" # skip the suffix with the comment ID |
| 57 | + PR_NUMBER="${PR_NUMBER##*/}" # skip the prefix before the PR number |
| 58 | +
|
| 59 | + export GH_TOKEN="${{ secrets.GITHUB_TOKEN }}" |
| 60 | + eval "$(gh api repos/gitgitgadget/git/pulls/$PR_NUMBER \ |
| 61 | + --jq '"head_sha=\(.head.sha) && repo=\(.base.repo.full_name)"')" |
| 62 | + echo "head_sha=$head_sha" >> $GITHUB_OUTPUT |
| 63 | + echo "repo=$repo" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + export GH_TOKEN="$(case "$repo" in |
| 66 | + gitgitgadget/git) echo "${{ steps.gitgitgadget-git-token.outputs.token }}";; |
| 67 | + git/git) echo "${{ steps.git-git-token.outputs.token }}";; |
| 68 | + dscho/git) echo "${{ steps.dscho-git-token.outputs.token }}";; |
| 69 | + *) echo "${{ secrets.GITHUB_TOKEN }}";; |
| 70 | + esac |
| 71 | + )" |
| 72 | + eval "$(gh api repos/$repo/check-runs -X POST \ |
| 73 | + -f name='handle_pr_comment' \ |
| 74 | + -f head_sha="$head_sha" \ |
| 75 | + -f status='in_progress' \ |
| 76 | + -f details_url="$details_url" \ |
| 77 | + -f "output[title]=$title" \ |
| 78 | + -f "output[summary]=$summary" \ |
| 79 | + -f "output[text]=$text" \ |
| 80 | + --jq '"check_run_id=\(.id)"')" |
| 81 | + echo "check_run_id=$check_run_id" >> $GITHUB_OUTPUT |
| 82 | + - uses: gitgitgadget/gitgitgadget/handle-pr-comment@v1 |
| 83 | + with: |
| 84 | + pr-repo-token: ${{ steps.gitgitgadget-git-token.outputs.token }} |
| 85 | + upstream-repo-token: ${{ steps.git-git-token.outputs.token }} |
| 86 | + test-repo-token: ${{ steps.dscho-git-token.outputs.token }} |
| 87 | + smtp-host: smtp.gmail.com |
| 88 | + |
| 89 | + smtp-pass: "${{ secrets.GITGITGADGET_SMTP_PASS }}" |
| 90 | + pr-comment-url: ${{ env.PR_COMMENT_URL }} |
| 91 | + - name: update the check run |
| 92 | + if: always() && steps.create-check-run.outputs.check_run_id != '' |
| 93 | + run: | |
| 94 | + export GH_TOKEN="$(case "${{ steps.create-check-run.outputs.repo }}" in |
| 95 | + gitgitgadget/git) echo "${{ steps.gitgitgadget-git-token.outputs.token }}";; |
| 96 | + git/git) echo "${{ steps.git-git-token.outputs.token }}";; |
| 97 | + dscho/git) echo "${{ steps.dscho-git-token.outputs.token }}";; |
| 98 | + *) echo "${{ secrets.GITHUB_TOKEN }}";; |
| 99 | + esac |
| 100 | + )" |
| 101 | + gh api repos/${{ steps.create-check-run.outputs.repo }}/check-runs/${{ steps.create-check-run.outputs.check_run_id }} \ |
| 102 | + -X PATCH \ |
| 103 | + -f status='completed' \ |
| 104 | + -f conclusion='${{ job.status }}' \ |
| 105 | + -f 'output[title]=${{ steps.create-check-run.outputs.title }}' \ |
| 106 | + -f 'output[summary]=${{ steps.create-check-run.outputs.summary }}' \ |
| 107 | + -f 'output[text]=${{ steps.create-check-run.outputs.text }}' |
0 commit comments