|
| 1 | +name: PR acknowledgement |
| 2 | + |
| 3 | +# Posts one acknowledgement comment when a pull request is opened, so a |
| 4 | +# contributor learns the current review status immediately instead of inferring |
| 5 | +# it from silence. |
| 6 | +# |
| 7 | +# The message text lives in `.github/pr-acknowledgement.md`. Edit that file to |
| 8 | +# change what is said; blank it (or delete it) to turn acknowledgements off |
| 9 | +# without touching this workflow. No code change is needed to switch it. |
| 10 | +# |
| 11 | +# SECURITY — this uses `pull_request_target`, which runs against the BASE repo |
| 12 | +# with a token that can write. That is required: a `pull_request` trigger gives |
| 13 | +# fork PRs a read-only token, so commenting on exactly the contributions we most |
| 14 | +# want to acknowledge would fail. |
| 15 | +# |
| 16 | +# The safety rule that makes it sound: this job NEVER checks out, builds, or |
| 17 | +# executes pull-request code. `actions/checkout` here resolves to the base |
| 18 | +# commit (the default under `pull_request_target`), and it is used only to read |
| 19 | +# the message file out of our own tree. Do not add a `ref:` pointing at the PR |
| 20 | +# head, and do not add a build step. Nothing from the PR is interpolated into a |
| 21 | +# shell command either — the body comes from a file, and the PR number is passed |
| 22 | +# through the environment rather than expanded inline. |
| 23 | + |
| 24 | +on: |
| 25 | + pull_request_target: |
| 26 | + types: [opened] |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + |
| 31 | +jobs: |
| 32 | + acknowledge: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + # Bots do not read comments, and acknowledging our own PRs is noise. |
| 35 | + if: >- |
| 36 | + github.event.pull_request.user.type != 'Bot' && |
| 37 | + github.event.pull_request.author_association != 'OWNER' |
| 38 | + permissions: |
| 39 | + pull-requests: write |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 42 | + with: |
| 43 | + # Base commit only — never the PR head. See the security note above. |
| 44 | + persist-credentials: false |
| 45 | + |
| 46 | + - name: Post acknowledgement |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ github.token }} |
| 49 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 50 | + REPO: ${{ github.repository }} |
| 51 | + run: | |
| 52 | + set -euo pipefail |
| 53 | + MESSAGE_FILE=.github/pr-acknowledgement.md |
| 54 | +
|
| 55 | + if [ ! -f "$MESSAGE_FILE" ]; then |
| 56 | + echo "No $MESSAGE_FILE in the base tree — acknowledgements are off." |
| 57 | + exit 0 |
| 58 | + fi |
| 59 | +
|
| 60 | + # An empty or whitespace-only file is the documented off switch. |
| 61 | + if [ -z "$(tr -d '[:space:]' < "$MESSAGE_FILE")" ]; then |
| 62 | + echo "$MESSAGE_FILE is blank — acknowledgements are off." |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | +
|
| 66 | + gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file "$MESSAGE_FILE" |
| 67 | + echo "Acknowledged PR #${PR_NUMBER}." |
0 commit comments