@@ -52,43 +52,44 @@ jobs:
5252 return;
5353 }
5454
55- // Same-repository review runs already ran with a privileged
56- // token and wrote their labels; only fork runs need the
57- // follow-up.
58- if (run.head_repository && run.head_repository.fork === false) {
59- core.info('Ignoring same-repository pull_request_review run');
60- return;
61- }
62-
63- // Resolve which PRs the completed run targeted. Fork runs
64- // backfill pull_requests empty, so fall back to the exact head
65- // owner, branch, and SHA lookup used by the resolve job of
66- // label-pr-review-state.yml. Keep both copies in sync.
55+ // GitHub reports the base repository as head_repository on
56+ // every pull_request_review run, fork PR or not (issue
57+ // #2133), so the payload cannot tell fork from same-repo
58+ // runs. Dispatching for a same-repo PR is idempotent: the
59+ // reconciliation writes the same labels, and its completion
60+ // carries event 'workflow_dispatch', which the guard above
61+ // filters out.
62+ //
63+ // Resolve which PRs the completed run targeted. Review runs
64+ // backfill pull_requests empty for fork PRs, and the head
65+ // owner is not recoverable from head_repository, so the
66+ // fallback lists open PRs and matches the exact head branch,
67+ // SHA, and base repository. The workflow_run branch of
68+ // label-pr-review-state.yml keeps an owner-and-branch query
69+ // instead: its runs are CI runs triggered by pull_request,
70+ // whose head_repository is the real fork.
6771 let prNumbers = [];
6872 if (run.pull_requests?.length > 0) {
6973 prNumbers = run.pull_requests.map(pr => pr.number);
70- } else {
71- const headOwner = run.head_repository?.owner?.login;
72- if (headOwner && run.head_branch && run.head_sha) {
73- const candidates = await github.paginate(github.rest.pulls.list, {
74- owner,
75- repo,
76- state: 'open',
77- head: `${headOwner}:${run.head_branch}`,
78- per_page: 100,
79- });
80- const baseRepository = `${owner}/${repo}`.toLowerCase();
81- prNumbers = candidates
82- .filter(pr =>
83- pr.head?.sha === run.head_sha &&
84- pr.base?.repo?.full_name?.toLowerCase() === baseRepository
85- )
86- .map(pr => pr.number);
87- core.info(
88- `Resolved workflow_run ${run.id ?? '(unknown)'} to ` +
89- `${prNumbers.length} PR(s) by exact head owner, branch, and SHA`
90- );
91- }
74+ } else if (run.head_branch && run.head_sha) {
75+ const candidates = await github.paginate(github.rest.pulls.list, {
76+ owner,
77+ repo,
78+ state: 'open',
79+ per_page: 100,
80+ });
81+ const baseRepository = `${owner}/${repo}`.toLowerCase();
82+ prNumbers = candidates
83+ .filter(pr =>
84+ pr.head?.sha === run.head_sha &&
85+ pr.head?.ref === run.head_branch &&
86+ pr.base?.repo?.full_name?.toLowerCase() === baseRepository
87+ )
88+ .map(pr => pr.number);
89+ core.info(
90+ `Resolved workflow_run ${run.id ?? '(unknown)'} to ` +
91+ `${prNumbers.length} PR(s) by exact head branch, SHA, and base repository`
92+ );
9293 }
9394
9495 // Each dispatch starts a privileged workflow_dispatch run of the
0 commit comments