Skip to content

Commit

Permalink
fix(manage-merge-queue): no_evict_upon_conflict input (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Sep 12, 2024
1 parent 869bc24 commit 72973b2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 19 deletions.
18 changes: 11 additions & 7 deletions dist/676.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/676.index.js.map

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions src/helpers/prepare-queued-pr-for-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ export const updatePrWithDefaultBranch = async (pullRequest: PullRequest) => {
...context.repo
});
} catch (error) {
const noEvictUponConflict = core.getBooleanInput('no_evict_upon_conflict');
if ((error as GithubError).status === 409) {
if (!noEvictUponConflict) await removePrFromQueue(pullRequest);
core.setFailed('The first PR in the queue has a merge conflict.');
} else core.setFailed((error as GithubError).message);
const noEvictUponConflict = core.getInput('no_evict_upon_conflict');
const githubError = error as GithubError;
if (githubError.status !== 409) {
core.setFailed(githubError.message);
return;
}
if (noEvictUponConflict === 'true') {
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.');
return;
}

await removePrFromQueue(pullRequest);
core.setFailed('The first PR in the queue has a merge conflict, and it was removed from the queue.');
}
};
56 changes: 50 additions & 6 deletions test/helpers/prepare-queued-pr-for-merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import { FIRST_QUEUED_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL, READY_FOR_MERGE_PR_LABE
import { Mocktokit } from '../types';
import { context } from '@actions/github';
import { octokit } from '../../src/octokit';
import { updateMergeQueue } from '../../src/utils/update-merge-queue';
import { prepareQueuedPrForMerge } from '../../src/helpers/prepare-queued-pr-for-merge';
import { removePrFromQueue } from '../../src/helpers/manage-merge-queue';
import { removeLabelIfExists } from '../../src/helpers/remove-label';

jest.mock('@actions/core');
jest.mock('../../src/utils/update-merge-queue');
Expand Down Expand Up @@ -348,14 +346,60 @@ describe('prepareQueuedPrForMerge', () => {
: { data: [] }
);
(octokit.repos.merge as unknown as Mocktokit).mockRejectedValue({ status: 409 });
(core.getBooleanInput as jest.Mock).mockReturnValue(true);
(core.getInput as jest.Mock).mockReturnValue('true');
await prepareQueuedPrForMerge();
});

it('should NOT remove PR from queue and call core.error', () => {
it('should NOT remove PR from queue and call core.info', () => {
expect(removePrFromQueue).not.toHaveBeenCalled();
expect(removeLabelIfExists).not.toHaveBeenCalled();
expect(updateMergeQueue).not.toHaveBeenCalled();
expect(core.info).toHaveBeenCalled();
});
});

describe('merge conflict without no_evict_upon_conflict', () => {
const firstInQueue = {
number: 123,
head: {
ref
},
state: 'open',
labels: [
{
name: READY_FOR_MERGE_PR_LABEL
},
{
name: FIRST_QUEUED_PR_LABEL
}
]
};
beforeEach(async () => {
(octokit.pulls.list as unknown as Mocktokit).mockImplementation(async ({ page }) =>
page === 1 || !page
? {
data: [
{
head: {
ref: 'other branch name'
},
state: 'open',
labels: [
{
name: 'CORE APPROVED'
}
]
},
firstInQueue
]
}
: { data: [] }
);
(octokit.repos.merge as unknown as Mocktokit).mockRejectedValue({ status: 409 });
(core.getInput as jest.Mock).mockReturnValue('');
await prepareQueuedPrForMerge();
});

it('should remove PR from queue and call core.error', () => {
expect(removePrFromQueue).toHaveBeenCalled();
expect(core.setFailed).toHaveBeenCalled();
});
});
Expand Down

0 comments on commit 72973b2

Please sign in to comment.