From c58eded00cce3afe7f4e7bce0de8a67b6cdce32a Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Fri, 31 Jul 2026 04:59:16 +0800 Subject: [PATCH] [ci] use head repo looking up pr_number (#13446) The API github.rest.repos.listPullRequestsAssociatedWithCommit() can only query commits from the repo owning those commits. Although a fork PR is pushed to the base repo, the base repo doesn't have the commit yet. This commit changes the workflow to query pull request from head repo. --- .github/workflows/size-report.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/size-report.yml b/.github/workflows/size-report.yml index e4deb4532..0c50b62a7 100644 --- a/.github/workflows/size-report.yml +++ b/.github/workflows/size-report.yml @@ -65,14 +65,22 @@ jobs: let pr_number = context.payload.workflow_run.pull_requests?.[0]?.number if (!pr_number) { + const head_repo = context.payload.workflow_run.head_repository?.full_name; + if (!head_repo) { + core.setFailed('Head repository not found in workflow run context payload.'); + return; + } + const [owner, repo] = head_repo.split('/') const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ - owner: context.repo.owner, - repo: context.repo.repo, + owner, + repo, commit_sha: context.payload.workflow_run.head_sha, }) - const open_pr = prs?.find(pr => pr.state === 'open') || prs?.[0] - if (open_pr) { - pr_number = open_pr.number + const base_full_name = `${context.repo.owner}/${context.repo.repo}` + const pr = prs?.find(pr => pr.base.repo.full_name === base_full_name && pr.state === 'open') || + prs?.find(pr => pr.base.repo.full_name === base_full_name); + if (pr) { + pr_number = pr.number } }