|
| 1 | +# Description: This workflow is triggered when the `receive-pr` workflow completes to post suggestions on the PR. |
| 2 | +# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code. |
| 3 | +# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 4 | +--- |
| 5 | +name: comment-pr |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: ["receive-pr"] |
| 10 | + types: |
| 11 | + - completed |
| 12 | + |
| 13 | +jobs: |
| 14 | + post-suggestions: |
| 15 | + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow |
| 16 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 17 | + runs-on: ubuntu-latest |
| 18 | + env: |
| 19 | + # https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token |
| 20 | + ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + timeout-minutes: 10 |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + ref: ${{github.event.workflow_run.head_branch}} |
| 26 | + repository: ${{github.event.workflow_run.head_repository.full_name}} |
| 27 | + |
| 28 | + # Download the patch |
| 29 | + - uses: actions/download-artifact@v4 |
| 30 | + with: |
| 31 | + name: patch |
| 32 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + run-id: ${{ github.event.workflow_run.id }} |
| 34 | + - name: Apply patch |
| 35 | + run: | |
| 36 | + git apply git-diff.patch --allow-empty |
| 37 | + rm git-diff.patch |
| 38 | +
|
| 39 | + # Download the PR number |
| 40 | + - uses: actions/download-artifact@v4 |
| 41 | + with: |
| 42 | + name: pr_number |
| 43 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run-id: ${{ github.event.workflow_run.id }} |
| 45 | + - name: Read pr_number.txt |
| 46 | + run: | |
| 47 | + PR_NUMBER=$(cat pr_number.txt) |
| 48 | + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV |
| 49 | + rm pr_number.txt |
| 50 | +
|
| 51 | + # Post suggestions as a comment on the PR |
| 52 | + - uses: googleapis/code-suggester@v4 |
| 53 | + with: |
| 54 | + command: review |
| 55 | + pull_number: ${{ env.PR_NUMBER }} |
| 56 | + git_dir: '.' |
0 commit comments