Skip to content

Commit

Permalink
Merge pull request #137 from oat-sa/fix/recover-from-failed-branch-de…
Browse files Browse the repository at this point in the history
…letions

Fix/recover from failed branch deletions
  • Loading branch information
oatymart authored Sep 12, 2024
2 parents a855ca6 + 36ef73d commit 82a8983
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,11 @@ export default function taoExtensionReleaseFactory(params = {}) {
log.doing('Clean up the place');

try {
await gitClient.deleteBranch(data.releasingBranch);
await gitClient.deleteBranch(data.releasingBranch);
} catch (error) {
if (error.message.includes('remote ref does not exist')) {
// If a github setting auto-deleted the closed PR branch on the remote before this step,
// these are some of the observed error messages
if (error.message.includes('remote ref does not exist') || error.message.includes('unable to resolve reference')) {
log.warn(`Cannot delete branch ${data.releasingBranch}: ${error} - ${error.stack}`);
} else {
throw error;
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/release/removeReleasingBranch/release.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ describe('src/release.js removeReleasingBranch', () => {
expect(deleteBranch).toBeCalledWith(`${branchPrefix}-${version}`);
});
test('should bypass error deleting release branch when it does not exist', async () => {
expect.assertions(2);
expect.assertions(4);

const deleteBranch = jest.fn();

deleteBranch.mockImplementationOnce(() => {
throw new Error('remote ref does not exist');
}).mockImplementationOnce(() => {
throw new Error('[remote rejected] (cannot lock ref \'refs/heads/release-4.0.0\': unable to resolve reference \'refs/heads/release-4.0.0\'');
});

git.mockImplementationOnce(() => {
git.mockImplementation(() => {
return {
deleteBranch
};
Expand All @@ -120,6 +122,13 @@ describe('src/release.js removeReleasingBranch', () => {

expect(deleteBranch).toBeCalledTimes(1);
expect(deleteBranch).toBeCalledWith(`${branchPrefix}-${version}`);

deleteBranch.mockClear();

await release.removeReleasingBranch();

expect(deleteBranch).toBeCalledTimes(1);
expect(deleteBranch).toBeCalledWith(`${branchPrefix}-${version}`);
});
test('should not bypass error deleting release branch when another error', async () => {
expect.assertions(3);
Expand Down

0 comments on commit 82a8983

Please sign in to comment.