Reliable PR number relay for labeler workflow (#8628)

This commit is contained in:
I am just a bot
2025-09-13 12:17:09 +02:00
committed by GitHub
parent 47519373a6
commit 6e11920bf3
2 changed files with 18 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
name: PR review labeler
on:
workflow_run:
workflows: ["PR review listener"] # must match the other workflow's name
workflows: ["PR review listener"]
types: [completed]
jobs:
@@ -14,30 +14,18 @@ jobs:
pull-requests: write
steps:
- name: Resolve PR number from head_sha
id: pr
uses: actions/github-script@v7
- name: Download PR number artifact from upstream run
uses: actions/download-artifact@v4
with:
script: |
const { owner, repo } = context.repo;
const sha = context.payload.workflow_run.head_sha;
name: pr-number-${{ github.event.workflow_run.id }} # same unique name
path: .
run-id: ${{ github.event.workflow_run.id }} # ← CRITICAL: fetch from the upstream run
github-token: ${{ secrets.GITHUB_TOKEN }}
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner, repo, commit_sha: sha
});
if (!prs.length) {
core.setFailed(`❌ No PR found for commit ${sha}`);
return;
}
// Pick an open PR if possible
const pr = prs.find(p => p.state === 'open') || prs[0];
core.info(`Using PR #${pr.number}`);
core.setOutput('number', String(pr.number));
- id: pr
run: echo "number=$(cat pr.txt)" >> $GITHUB_OUTPUT
- name: Label when approved
if: ${{ success() }}
uses: j-fulbright/label-when-approved-action@v1.2
with:
token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -6,10 +6,15 @@ on:
jobs:
ping:
if: ${{ github.event.review.state == 'approved' }}
name: "Listen"
runs-on: ubuntu-latest
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- run:
echo "Approved review detected for PR ${{ github.event.pull_request.number }}"
- name: Save PR number
run: echo "${{ github.event.pull_request.number }}" > pr.txt
- uses: actions/upload-artifact@v4
with:
# unique name: includes workflow run id
name: pr-number-${{ github.run_id }}
path: pr.txt