From 6e226146488d3f3e51df95d6a8ea128c0d4bd10c Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Thu, 19 Mar 2026 21:15:48 +0000 Subject: [PATCH] ci: resolve PR number for artifact comment --- .github/workflows/comment-pr-artifacts.yml | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/comment-pr-artifacts.yml b/.github/workflows/comment-pr-artifacts.yml index b50a4146..deaed7da 100644 --- a/.github/workflows/comment-pr-artifacts.yml +++ b/.github/workflows/comment-pr-artifacts.yml @@ -28,10 +28,29 @@ jobs: const repo = context.repo.repo; const prs = run.pull_requests || []; - const prNumber = prs[0]?.number; + let prNumber = prs[0]?.number; + + // `workflow_run` payload does not reliably include pull request numbers. + // Resolve PR number(s) by asking GitHub for PRs associated with the head SHA. if (!prNumber) { - core.info('No PR number found for this workflow_run; skipping.'); - return; + const headSha = run.head_sha; + if (!headSha) { + core.info('No PR number and no head_sha found for this workflow_run; skipping.'); + return; + } + + const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner, + repo, + commit_sha: headSha, + }); + + const open = (associated.data || []).find((p) => p.state === 'open'); + prNumber = open?.number; + if (!prNumber) { + core.info(`No open PR found associated with commit ${headSha}; skipping.`); + return; + } } // Only comment when the PR build job actually ran (i.e. authorization passed).