From de7973af55cdcacc69b5be2cc3730b71049ddf94 Mon Sep 17 00:00:00 2001 From: Gutemberg Ribeiro Date: Wed, 15 Jul 2026 22:25:21 +0100 Subject: [PATCH] [CI] Fix PR artifact-links comment for fork PRs (#227) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The workflow resolved the PR from workflow_run.pull_requests or the head commit, both of which come back empty for PRs from forks — so it logged "No open PR for this build" and never commented. Resolve the PR by its head "owner:branch" (from workflow_run.head_repository/head_branch), which works for forks, keeping the commit-association path as a fallback. --- .github/workflows/pr-build-links.yml | 31 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-build-links.yml b/.github/workflows/pr-build-links.yml index 3a5b978..2e07020 100644 --- a/.github/workflows/pr-build-links.yml +++ b/.github/workflows/pr-build-links.yml @@ -39,21 +39,36 @@ jobs: const run = context.payload.workflow_run; const { owner, repo } = context.repo; - // Fork PRs leave workflow_run.pull_requests empty, so fall back to - // resolving the PR from the build's head commit. + // Resolve the PR. Same-repo PRs are in workflow_run.pull_requests, but + // fork PRs leave it empty AND their head commit is not on a base-repo + // branch, so listPullRequestsAssociatedWithCommit misses them too. Match + // the open PR by its head "owner:branch" instead, which works for forks. let prNumber; if (run.pull_requests && run.pull_requests.length > 0) { prNumber = run.pull_requests[0].number; } else { - const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ - owner, repo, commit_sha: run.head_sha, - }); - const open = prs.data.find(pr => pr.state === 'open'); - if (!open) { + let candidates = []; + const headOwner = run.head_repository && run.head_repository.owner + ? run.head_repository.owner.login + : null; + if (headOwner && run.head_branch) { + const byHead = await github.rest.pulls.list({ + owner, repo, state: 'open', + head: `${headOwner}:${run.head_branch}`, per_page: 10, + }); + candidates = byHead.data; + } + if (candidates.length === 0) { + const byCommit = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner, repo, commit_sha: run.head_sha, + }); + candidates = byCommit.data.filter(pr => pr.state === 'open'); + } + if (candidates.length === 0) { core.info('No open PR for this build; nothing to comment.'); return; } - prNumber = open.number; + prNumber = candidates[0].number; } // Collect the per-platform artifacts the build produced.