Skip to content
Snippets Groups Projects
Commit 393c24c6 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix: stop attempting branch merge if pr exists (#920)

parent 8b99ce52
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,10 @@ async function tryBranchAutomerge(config) { ...@@ -8,6 +8,10 @@ async function tryBranchAutomerge(config) {
if (!config.automerge || config.automergeType === 'pr') { if (!config.automerge || config.automergeType === 'pr') {
return 'no automerge'; return 'no automerge';
} }
const existingPr = config.api.getBranchPr(config.branchName);
if (existingPr) {
return 'automerge aborted - PR exists';
}
const branchStatus = await config.api.getBranchStatus( const branchStatus = await config.api.getBranchStatus(
config.branchName, config.branchName,
config.requiredStatusChecks config.requiredStatusChecks
......
...@@ -8,7 +8,11 @@ describe('workers/branch/automerge', () => { ...@@ -8,7 +8,11 @@ describe('workers/branch/automerge', () => {
beforeEach(() => { beforeEach(() => {
config = { config = {
...defaultConfig, ...defaultConfig,
api: { getBranchStatus: jest.fn(), mergeBranch: jest.fn() }, api: {
getBranchPr: jest.fn(),
getBranchStatus: jest.fn(),
mergeBranch: jest.fn(),
},
logger, logger,
}; };
}); });
...@@ -27,6 +31,15 @@ describe('workers/branch/automerge', () => { ...@@ -27,6 +31,15 @@ describe('workers/branch/automerge', () => {
config.api.getBranchStatus.mockReturnValueOnce('pending'); config.api.getBranchStatus.mockReturnValueOnce('pending');
expect(await tryBranchAutomerge(config)).toBe('no automerge'); expect(await tryBranchAutomerge(config)).toBe('no automerge');
}); });
it('returns false if PR exists', async () => {
config.api.getBranchPr.mockReturnValueOnce({});
config.automerge = true;
config.automergeType = 'branch-push';
config.api.getBranchStatus.mockReturnValueOnce('success');
expect(await tryBranchAutomerge(config)).toBe(
'automerge aborted - PR exists'
);
});
it('returns false if automerge fails', async () => { it('returns false if automerge fails', async () => {
config.automerge = true; config.automerge = true;
config.automergeType = 'branch-push'; config.automergeType = 'branch-push';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment