Skip to content

Commit

Permalink
Merge pull request #134 from oat-sa/fix/supress-error-deleting-branch
Browse files Browse the repository at this point in the history
fix: suppress error deleting branch in case it already exists
  • Loading branch information
gabrielfs7 authored Jun 19, 2024
2 parents d11fa8b + 99c3da8 commit 1160a28
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ So the command `taoRelease` will use the sources.
Useful commands :

- `npm test` runs the test suite
- `npx jest -- my-test.spec.js` runs a single test
- `npm run test:cov` runs the test suite with code coverage
- `npm run test:dev` runs the test suite in watch mode
- `npm run lint` verifies the sources complies with the code style guide
Expand Down
10 changes: 9 additions & 1 deletion src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,15 @@ export default function taoExtensionReleaseFactory(params = {}) {
async removeReleasingBranch() {
log.doing('Clean up the place');

await gitClient.deleteBranch(data.releasingBranch);
try {
await gitClient.deleteBranch(data.releasingBranch);
} catch (error) {
if (error.message.includes('remote ref does not exist')) {
log.warn(`Cannot delete branch ${data.releasingBranch}: ${error} - ${error.stack}`);
} else {
throw error;
}
}

log.done();
},
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/release/removeReleasingBranch/release.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,49 @@ describe('src/release.js removeReleasingBranch', () => {
expect(deleteBranch).toBeCalledTimes(1);
expect(deleteBranch).toBeCalledWith(`${branchPrefix}-${version}`);
});
test('should bypass error deleting release branch when it does not exist', async () => {
expect.assertions(2);

const deleteBranch = jest.fn();

deleteBranch.mockImplementationOnce(() => {
throw new Error('remote ref does not exist');
});

git.mockImplementationOnce(() => {
return {
deleteBranch
};
});

const release = releaseFactory(branchPrefix);
release.setData({ releasingBranch, token, extension: {} });
await release.initialiseGitClient();
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);

const deleteBranch = jest.fn();

deleteBranch.mockImplementationOnce(() => {
throw new Error('Some other error');
});

git.mockImplementationOnce(() => {
return {
deleteBranch
};
});

const release = releaseFactory(branchPrefix);
release.setData({ releasingBranch, token, extension: {} });
await release.initialiseGitClient();
await expect(() => release.removeReleasingBranch()).rejects.toThrowError('Some other error');
expect(deleteBranch).toBeCalledTimes(1);
expect(deleteBranch).toBeCalledWith(`${branchPrefix}-${version}`);
});
});

0 comments on commit 1160a28

Please sign in to comment.