Skip to content

Commit c409c4b

Browse files
authored
Refactor PR lookup to use head SHA for accuracy
1 parent 3da9b17 commit c409c4b

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

.github/workflows/pr-comment.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ jobs:
2020
with:
2121
script: |
2222
const runId = context.payload.workflow_run.id;
23-
const pr = context.payload.workflow_run.pull_requests[0];
23+
const headSha = context.payload.workflow_run.head_sha;
24+
25+
// Look up the PR by head SHA — works for fork PRs too
26+
const prs = await github.rest.pulls.list({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
state: 'open',
30+
sort: 'updated',
31+
per_page: 20,
32+
});
33+
const pr = prs.data.find(p => p.head.sha === headSha);
2434
if (!pr) {
25-
console.log('No PR associated, skipping.');
35+
console.log(`No open PR found for SHA ${headSha}, skipping.`);
2636
return;
2737
}
2838

0 commit comments

Comments
 (0)