File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,14 +42,14 @@ jobs:
4242 // Derive the target PR from the trusted workflow_run payload.
4343 let prNumber = run.pull_requests?.[0]?.number;
4444 if (!prNumber) {
45- // Fork PRs: workflow_run.pull_requests is empty, so resolve the PR
46- // from the head commit SHA.
47- const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
45+ const headOwner = run.head_repository?.owner?.login ?? context.repo.owner;
46+ const { data: prs } = await github.rest.pulls.list({
4847 owner: context.repo.owner,
4948 repo: context.repo.repo,
50- commit_sha: run.head_sha,
49+ state: 'all',
50+ head: `${headOwner}:${run.head_branch}`,
5151 });
52- prNumber = prs.find((p) => p.state === 'open' )?.number;
52+ prNumber = ( prs.find((p) => p.head?.sha === run.head_sha) ?? prs[0] )?.number;
5353 }
5454 if (!Number.isInteger(prNumber)) {
5555 core.setFailed(`Could not resolve a PR for workflow_run ${run.id} (head_sha ${run.head_sha})`);
You can’t perform that action at this time.
0 commit comments