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 name: PR review labeler
on: on:
workflow_run: workflow_run:
workflows: ["PR review listener"] # must match the other workflow's name workflows: ["PR review listener"]
types: [completed] types: [completed]
jobs: jobs:
@@ -14,30 +14,18 @@ jobs:
pull-requests: write pull-requests: write
steps: steps:
- name: Resolve PR number from head_sha - name: Download PR number artifact from upstream run
id: pr uses: actions/download-artifact@v4
uses: actions/github-script@v7
with: with:
script: | name: pr-number-${{ github.event.workflow_run.id }} # same unique name
const { owner, repo } = context.repo; path: .
const sha = context.payload.workflow_run.head_sha; 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({ - id: pr
owner, repo, commit_sha: sha run: echo "number=$(cat pr.txt)" >> $GITHUB_OUTPUT
});
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));
- name: Label when approved - name: Label when approved
if: ${{ success() }}
uses: j-fulbright/label-when-approved-action@v1.2 uses: j-fulbright/label-when-approved-action@v1.2
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -6,10 +6,15 @@ on:
jobs: jobs:
ping: ping:
if: ${{ github.event.review.state == 'approved' }} if: ${{ github.event.review.state == 'approved' }}
name: "Listen" runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
runs-on: ubuntu-latest
steps: steps:
- run: - name: Save PR number
echo "Approved review detected for PR ${{ github.event.pull_request.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