From 0a22119a25e5258b0eb9eae6f95b5d7539dec92b Mon Sep 17 00:00:00 2001 From: Marcelo Gobetti Date: Wed, 4 Mar 2026 14:11:51 -0300 Subject: [PATCH] Handle missing pull_request payload when triggered via workflow_call context.payload.pull_request is undefined for workflow_call events, causing TypeError on .number. Fall back to looking up the open PR by branch ref via the REST API. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/auto-fill-pr.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-fill-pr.yml b/.github/workflows/auto-fill-pr.yml index db3cbf1..d5e69e0 100644 --- a/.github/workflows/auto-fill-pr.yml +++ b/.github/workflows/auto-fill-pr.yml @@ -198,11 +198,30 @@ jobs: const claudeSuccess = '${{ steps.claude.outputs.success }}' === 'true'; const testingSuccess = '${{ steps.testing.outputs.success }}' === 'true'; + // Get PR number - context.payload.pull_request is undefined for workflow_call + let prNumber; + if (context.payload.pull_request) { + prNumber = context.payload.pull_request.number; + } else { + const ref = context.ref.replace('refs/heads/', ''); + const { data: prs } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: `${context.repo.owner}:${ref}` + }); + if (prs.length === 0) { + core.warning('No open PR found for this branch, skipping PR update'); + return; + } + prNumber = prs[0].number; + } + // Get existing PR body const { data: pr } = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: context.payload.pull_request.number + pull_number: prNumber }); const existingBody = pr.body || ''; @@ -320,7 +339,7 @@ jobs: await github.rest.pulls.update({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: context.payload.pull_request.number, + pull_number: prNumber, body: newBody }); } \ No newline at end of file