[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.
This commit is contained in:
Yakun Xu
2026-07-30 13:59:16 -07:00
committed by GitHub
parent ae18b66d2e
commit c58eded00c
+13 -5
View File
@@ -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
}
}