Skip to content

Commit d893140

Browse files
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.
1 parent a96444d commit d893140

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Bug Fixes
6+
7+
- Added handling for "Reference does not exist" error during rebasing to prevent action failures when a reference (branch or commit) no longer exists
8+
39
## v0.2.0 (2025-08-05)
410

511
### Dependencies Updated

src/Rebaser/__tests__/rebaser.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ test('Failing rebase due to head base change completes successfully', async () =
8181
expect(error).toBeNull();
8282
});
8383

84+
test('Failing rebase due to reference not existing completes successfully', async () => {
85+
/* Given */
86+
testGithubRebase.result = Promise.reject('HttpError: Reference does not exist');
87+
88+
let error = null;
89+
90+
/* When */
91+
try {
92+
await rebaser.rebasePullRequests([
93+
{
94+
ownerName: 'owner',
95+
repoName: 'repo',
96+
number: 3,
97+
draft: false,
98+
rebaseable: true,
99+
mergeableState: 'behind',
100+
labels: [],
101+
},
102+
]);
103+
} catch (e) {
104+
error = e;
105+
}
106+
107+
/* Then */
108+
expect(error).toBeNull();
109+
});
110+
84111
test('Failing rebase due unknown failure errors', async () => {
85112
/* Given */
86113
testGithubRebase.result = Promise.reject('Some unknown error');

src/Rebaser/rebaser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export class Rebaser {
3030
warning(`Rebase aborted because the head branch changed for ${JSON.stringify(pullRequest)}`);
3131
return;
3232
}
33+
if (String(e).includes('Reference does not exist')) {
34+
warning(`Reference does not exist for ${JSON.stringify(pullRequest)}. The branch may have been deleted or modified.`);
35+
return;
36+
}
3337
throw new Error(`Error while rebasing for ${JSON.stringify(pullRequest)}: ${String(e)}`);
3438
}
3539
}

0 commit comments

Comments
 (0)