From d893140d83c10d591dca76c6de0e598f3495371c Mon Sep 17 00:00:00 2001 From: "jetbrains-junie[bot]" Date: Wed, 6 Aug 2025 08:24:06 +0000 Subject: [PATCH] fix(rebaser): handle 'Reference does not exist' error Specific error handling for the "Reference does not exist" error was added in the `rebaser.ts` file to prevent the GitHub Action from failing when a referenced branch or commit does not exist. A corresponding test was implemented in `rebaser.test.ts` to ensure this error is handled gracefully. Additionally, the CHANGELOG.md was updated to document the fix. --- CHANGELOG.md | 6 ++++++ src/Rebaser/__tests__/rebaser.test.ts | 27 +++++++++++++++++++++++++++ src/Rebaser/rebaser.ts | 4 ++++ 3 files changed, 37 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c69edf0..ec579bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Bug Fixes + +- Added handling for "Reference does not exist" error during rebasing to prevent action failures when a reference (branch or commit) no longer exists + ## v0.2.0 (2025-08-05) ### Dependencies Updated diff --git a/src/Rebaser/__tests__/rebaser.test.ts b/src/Rebaser/__tests__/rebaser.test.ts index 61d54b4..77fd7d6 100644 --- a/src/Rebaser/__tests__/rebaser.test.ts +++ b/src/Rebaser/__tests__/rebaser.test.ts @@ -81,6 +81,33 @@ test('Failing rebase due to head base change completes successfully', async () = expect(error).toBeNull(); }); +test('Failing rebase due to reference not existing completes successfully', async () => { + /* Given */ + testGithubRebase.result = Promise.reject('HttpError: Reference does not exist'); + + let error = null; + + /* When */ + try { + await rebaser.rebasePullRequests([ + { + ownerName: 'owner', + repoName: 'repo', + number: 3, + draft: false, + rebaseable: true, + mergeableState: 'behind', + labels: [], + }, + ]); + } catch (e) { + error = e; + } + + /* Then */ + expect(error).toBeNull(); +}); + test('Failing rebase due unknown failure errors', async () => { /* Given */ testGithubRebase.result = Promise.reject('Some unknown error'); diff --git a/src/Rebaser/rebaser.ts b/src/Rebaser/rebaser.ts index 28c2d94..7e0853d 100644 --- a/src/Rebaser/rebaser.ts +++ b/src/Rebaser/rebaser.ts @@ -30,6 +30,10 @@ export class Rebaser { warning(`Rebase aborted because the head branch changed for ${JSON.stringify(pullRequest)}`); return; } + if (String(e).includes('Reference does not exist')) { + warning(`Reference does not exist for ${JSON.stringify(pullRequest)}. The branch may have been deleted or modified.`); + return; + } throw new Error(`Error while rebasing for ${JSON.stringify(pullRequest)}: ${String(e)}`); } }