From 14c33fc2a235503b3db4b18ea0e94b2b1b36b94e Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Tue, 14 Jul 2026 08:46:58 +0100 Subject: [PATCH] fix(ci): resolve PR number for fork PR plugin uploads The upload-pr-plugin workflow_run job failed at 'Resolve workflow run context' for fork PRs. GitHub leaves workflow_run.pull_requests empty for fork-originated runs, and listPullRequestsAssociatedWithCommit returns nothing because the head commit lives in the fork, not the base repo, so it hit core.setFailed. Match the run's head_sha against open PRs (pr.head.sha is the fork commit) before falling back to the commits API. --- .github/workflows/upload-pr-plugin.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/upload-pr-plugin.yml b/.github/workflows/upload-pr-plugin.yml index 6443c1376f..6a547fbe66 100644 --- a/.github/workflows/upload-pr-plugin.yml +++ b/.github/workflows/upload-pr-plugin.yml @@ -33,13 +33,30 @@ jobs: script: | const workflowRun = context.payload.workflow_run; const runId = workflowRun.id; + const headSha = workflowRun.head_sha; + + // Same-repo PRs populate this directly. let prNumber = workflowRun.pull_requests?.[0]?.number; + // Fork PRs leave pull_requests empty. Match the run's head commit + // against open PRs; pr.head.sha is the fork commit, so this works + // across repositories where the commits API cannot. + if (!prNumber) { + const pulls = await github.paginate(github.rest.pulls.list, { + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + per_page: 100, + }); + prNumber = pulls.find((pr) => pr.head.sha === headSha)?.number; + } + + // Last resort: only finds same-repo commits. if (!prNumber) { const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ owner: context.repo.owner, repo: context.repo.repo, - commit_sha: workflowRun.head_sha, + commit_sha: headSha, }); prNumber = prs.data[0]?.number; }