Repository navigation
Comment on pull request post pull request auto review #746
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Comment on pull request post pull request auto review | |
| on: | |
| workflow_run: | |
| workflows: ["Checking CLA Signature"] | |
| types: [completed] | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| comment: | |
| if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: cla-comment-${{ github.event.workflow_run.head_repository.id }}-${{ github.event.workflow_run.head_branch }} | |
| cancel-in-progress: false | |
| steps: | |
| - name: Acknowledge the verified pull request | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const run = context.payload.workflow_run; | |
| const source = run.head_repository; | |
| if (!source || !run.head_branch) { | |
| core.info("The verified source branch is no longer available."); | |
| return; | |
| } | |
| const {data: pulls} = await github.rest.pulls.list({ | |
| ...context.repo, | |
| state: "open", | |
| base: context.payload.repository.default_branch, | |
| head: source.owner.login + ":" + run.head_branch | |
| }); | |
| const pull = pulls.find(pr => pr.head.repo?.id === source.id && pr.head.sha === run.head_sha); | |
| if (!pull) { | |
| core.info("The verified commit no longer heads an open pull request."); | |
| return; | |
| } | |
| const target = {...context.repo, issue_number: pull.number}; | |
| const body = "## Thank You for making this pull request."; | |
| const pages = github.paginate.iterator(github.rest.issues.listComments, {...target, per_page: 100}); | |
| for await (const {data: comments} of pages) { | |
| if (comments.some(comment => comment.user?.login === "github-actions[bot]" && comment.body?.trim() === body)) { | |
| core.info("This pull request already has an acknowledgement."); | |
| return; | |
| } | |
| } | |
| await github.rest.issues.createComment({...target, body}); |