From b434a2232036bb32cc5fd3b8f28209f852c4155d Mon Sep 17 00:00:00 2001 From: BLACKBOX Agent Date: Thu, 6 Nov 2025 17:01:15 +0000 Subject: [PATCH] fix(core): handle undefined pull request in update operation --- dist/index.js | 7 +++++++ src/github-helper.ts | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/dist/index.js b/dist/index.js index 75ae3c2f07..c1038cb530 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1377,6 +1377,13 @@ class GitHubHelper { // Update the pull request that exists for this branch and base core.info(`Fetching existing pull request`); const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base })); + if (pulls.length === 0) { + throw new Error(`No open pull request found for head branch '${headBranch}' and base branch '${inputs.base}'. ` + + `This may occur if: (1) the pull request was already merged or closed, ` + + `(2) the token lacks sufficient permissions to list pull requests in this repository, or ` + + `(3) there is an issue with the branch reference format. ` + + `Please verify the pull request exists and the token has 'pull-requests: read' permission.`); + } core.info(`Attempting update of pull request`); const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number, title: inputs.title, body: inputs.body })); core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`); diff --git a/src/github-helper.ts b/src/github-helper.ts index 6d41e06d72..e60c56b2be 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -119,6 +119,17 @@ export class GitHubHelper { head: headBranch, base: inputs.base }) + + if (pulls.length === 0) { + throw new Error( + `No open pull request found for head branch '${headBranch}' and base branch '${inputs.base}'. ` + + `This may occur if: (1) the pull request was already merged or closed, ` + + `(2) the token lacks sufficient permissions to list pull requests in this repository, or ` + + `(3) there is an issue with the branch reference format. ` + + `Please verify the pull request exists and the token has 'pull-requests: read' permission.` + ) + } + core.info(`Attempting update of pull request`) const {data: pull} = await this.octokit.rest.pulls.update({ ...this.parseRepository(baseRepository),