Skip to content

Commit 72973b2

Browse files
authored
fix(manage-merge-queue): no_evict_upon_conflict input (#664)
1 parent 869bc24 commit 72973b2

File tree

4 files changed

+75
-19
lines changed

4 files changed

+75
-19
lines changed

dist/676.index.js

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/676.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/prepare-queued-pr-for-merge.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ export const updatePrWithDefaultBranch = async (pullRequest: PullRequest) => {
5858
...context.repo
5959
});
6060
} catch (error) {
61-
const noEvictUponConflict = core.getBooleanInput('no_evict_upon_conflict');
62-
if ((error as GithubError).status === 409) {
63-
if (!noEvictUponConflict) await removePrFromQueue(pullRequest);
64-
core.setFailed('The first PR in the queue has a merge conflict.');
65-
} else core.setFailed((error as GithubError).message);
61+
const noEvictUponConflict = core.getInput('no_evict_upon_conflict');
62+
const githubError = error as GithubError;
63+
if (githubError.status !== 409) {
64+
core.setFailed(githubError.message);
65+
return;
66+
}
67+
if (noEvictUponConflict === 'true') {
68+
core.info('The first PR in the queue has a merge conflict. PR was not removed from the queue due to no_evict_upon_conflict input.');
69+
return;
70+
}
71+
72+
await removePrFromQueue(pullRequest);
73+
core.setFailed('The first PR in the queue has a merge conflict, and it was removed from the queue.');
6674
}
6775
};

test/helpers/prepare-queued-pr-for-merge.test.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ import { FIRST_QUEUED_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL, READY_FOR_MERGE_PR_LABE
1616
import { Mocktokit } from '../types';
1717
import { context } from '@actions/github';
1818
import { octokit } from '../../src/octokit';
19-
import { updateMergeQueue } from '../../src/utils/update-merge-queue';
2019
import { prepareQueuedPrForMerge } from '../../src/helpers/prepare-queued-pr-for-merge';
2120
import { removePrFromQueue } from '../../src/helpers/manage-merge-queue';
22-
import { removeLabelIfExists } from '../../src/helpers/remove-label';
2321

2422
jest.mock('@actions/core');
2523
jest.mock('../../src/utils/update-merge-queue');
@@ -348,14 +346,60 @@ describe('prepareQueuedPrForMerge', () => {
348346
: { data: [] }
349347
);
350348
(octokit.repos.merge as unknown as Mocktokit).mockRejectedValue({ status: 409 });
351-
(core.getBooleanInput as jest.Mock).mockReturnValue(true);
349+
(core.getInput as jest.Mock).mockReturnValue('true');
352350
await prepareQueuedPrForMerge();
353351
});
354352

355-
it('should NOT remove PR from queue and call core.error', () => {
353+
it('should NOT remove PR from queue and call core.info', () => {
356354
expect(removePrFromQueue).not.toHaveBeenCalled();
357-
expect(removeLabelIfExists).not.toHaveBeenCalled();
358-
expect(updateMergeQueue).not.toHaveBeenCalled();
355+
expect(core.info).toHaveBeenCalled();
356+
});
357+
});
358+
359+
describe('merge conflict without no_evict_upon_conflict', () => {
360+
const firstInQueue = {
361+
number: 123,
362+
head: {
363+
ref
364+
},
365+
state: 'open',
366+
labels: [
367+
{
368+
name: READY_FOR_MERGE_PR_LABEL
369+
},
370+
{
371+
name: FIRST_QUEUED_PR_LABEL
372+
}
373+
]
374+
};
375+
beforeEach(async () => {
376+
(octokit.pulls.list as unknown as Mocktokit).mockImplementation(async ({ page }) =>
377+
page === 1 || !page
378+
? {
379+
data: [
380+
{
381+
head: {
382+
ref: 'other branch name'
383+
},
384+
state: 'open',
385+
labels: [
386+
{
387+
name: 'CORE APPROVED'
388+
}
389+
]
390+
},
391+
firstInQueue
392+
]
393+
}
394+
: { data: [] }
395+
);
396+
(octokit.repos.merge as unknown as Mocktokit).mockRejectedValue({ status: 409 });
397+
(core.getInput as jest.Mock).mockReturnValue('');
398+
await prepareQueuedPrForMerge();
399+
});
400+
401+
it('should remove PR from queue and call core.error', () => {
402+
expect(removePrFromQueue).toHaveBeenCalled();
359403
expect(core.setFailed).toHaveBeenCalled();
360404
});
361405
});

0 commit comments

Comments
 (0)