Skip to content

Commit

Permalink
only remove non-pending checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bherrmann2 committed Jul 9, 2024
1 parent 7aaf77c commit 59e9ba4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/helpers/remove-pr-from-merge-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const removePrFromMergeQueue = async ({ seconds }: RemovePrFromMergeQueue
...context.repo
});
const mostRecentStatus = orderBy(data, 'created_at', 'desc')[0];
if (mostRecentStatus && timestampIsStale(mostRecentStatus.created_at, seconds)) {
const noPendingStatus = data.find(status => status.state !== 'pending')
if (noPendingStatus && mostRecentStatus && timestampIsStale(mostRecentStatus.created_at, seconds)) {
core.info('Removing stale PR from first queued position...');
return Promise.all([removeLabelIfExists(READY_FOR_MERGE_PR_LABEL, number), removeLabelIfExists(FIRST_QUEUED_PR_LABEL, number)]);
}
Expand Down
41 changes: 41 additions & 0 deletions test/helpers/remove-pr-from-merge-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,47 @@ describe('removePrFromMergeQueue', () => {
});
});

describe('should not remove pr case with pending status', () => {
beforeEach(async () => {
(octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({
data: [
{
created_at: '2022-01-01T10:00:00Z',
state: 'failure'
},
{
created_at: '2022-01-01T09:01:00Z',
state: 'pending'
},
{
created_at: '2022-01-01T10:00:00Z',
state: 'success'
}
]
}));
await removePrFromMergeQueue({ seconds });
});

it('should call pulls.list with correct params', () => {
expect(octokit.pulls.list).toHaveBeenCalledWith({
state: 'open',
per_page: 100,
...context.repo
});
});

it('should call listCommitStatusesForRef with correct params', () => {
expect(octokit.repos.listCommitStatusesForRef).toHaveBeenCalledWith({
ref: 'correct sha',
...context.repo
});
});

it('should not call removeLabelIfExists', () => {
expect(removeLabelIfExists).not.toHaveBeenCalled();
});
});

describe('should remove stray PRs in the queue', () => {
beforeEach(async () => {
(octokit.pulls.list as unknown as Mocktokit).mockImplementation(async () => ({
Expand Down

0 comments on commit 59e9ba4

Please sign in to comment.