From 70c2f1afe59168c6191ceaedb6408b9bf6770f68 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 6 Jul 2026 01:12:08 -0700 Subject: [PATCH] ci: look up fork PRs via the head repository in type-diff-comment listPullRequestsAssociatedWithCommit returns nothing when the base repo is queried with a commit that only exists in a fork, so the PR resolution failed for exactly the fork PRs this workflow exists to serve (observed on #404: 'Unable to resolve PR for head SHA'). Query the workflow_run's head_repository instead, and filter the results to PRs that target this repo with the run's exact head SHA (the PR association returned by the API is authoritative, so a fork cannot spoof it). --- .github/workflows/type-diff-comment.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/type-diff-comment.yml b/.github/workflows/type-diff-comment.yml index d3c08408..08156c76 100644 --- a/.github/workflows/type-diff-comment.yml +++ b/.github/workflows/type-diff-comment.yml @@ -46,22 +46,28 @@ jobs: const run = context.payload.workflow_run; // Resolve the PR number. `workflow_run.pull_requests` is empty - // for fork PRs, so fall back to looking up open PRs by the run's - // head SHA. For `pull_request`-triggered runs the head SHA is the - // PR branch tip, but also match `merge_commit_sha` defensively in - // case it is the synthetic merge commit. + // for fork PRs, so fall back to looking up PRs by the run's head + // SHA. The commit lives in the HEAD repository (the fork), so the + // commit→PRs lookup must be done there — querying the base repo + // returns nothing for fork commits. Filter to PRs that target + // this repo and whose head is exactly the run's head SHA. let prNumber = run.pull_requests?.[0]?.number; if (!prNumber) { + const headOwner = + run.head_repository?.owner?.login ?? context.repo.owner; + const headRepo = run.head_repository?.name ?? context.repo.repo; const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ - owner: context.repo.owner, - repo: context.repo.repo, + owner: headOwner, + repo: headRepo, commit_sha: run.head_sha, }); + const baseFullName = `${context.repo.owner}/${context.repo.repo}`; const pr = prs.find( (p) => - p.head.sha === run.head_sha || - p.merge_commit_sha === run.head_sha, + p.base.repo.full_name === baseFullName && + (p.head.sha === run.head_sha || + p.merge_commit_sha === run.head_sha), ); prNumber = pr?.number; }