From f6a76af965336b9e572263b8a512275e83abb2dc Mon Sep 17 00:00:00 2001 From: Brad Herrmann Date: Thu, 11 Jul 2024 13:28:33 -0500 Subject: [PATCH] fix(remove-pr-from-merge-queue): check last update time before starting the stale check clock --- src/helpers/remove-pr-from-merge-queue.ts | 4 ++-- test/helpers/remove-pr-from-merge-queue.test.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/helpers/remove-pr-from-merge-queue.ts b/src/helpers/remove-pr-from-merge-queue.ts index a123eaef..6bcdea55 100644 --- a/src/helpers/remove-pr-from-merge-queue.ts +++ b/src/helpers/remove-pr-from-merge-queue.ts @@ -55,9 +55,9 @@ export const removePrFromMergeQueue = async ({ seconds }: RemovePrFromMergeQueue ref: sha, ...context.repo }); - const mostRecentStatus = orderBy(data, 'created_at', 'desc')[0]; + const mostRecentStatus = orderBy(data, 'updated_at', 'desc')[0]; const noPendingStatus = data.find(status => status.state !== 'pending'); - if (noPendingStatus && mostRecentStatus && timestampIsStale(mostRecentStatus.created_at, seconds)) { + if (noPendingStatus && mostRecentStatus && timestampIsStale(mostRecentStatus.updated_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)]); } diff --git a/test/helpers/remove-pr-from-merge-queue.test.ts b/test/helpers/remove-pr-from-merge-queue.test.ts index 52eeb738..0b3034ee 100644 --- a/test/helpers/remove-pr-from-merge-queue.test.ts +++ b/test/helpers/remove-pr-from-merge-queue.test.ts @@ -58,11 +58,11 @@ describe('removePrFromMergeQueue', () => { (octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({ data: [ { - created_at: '2022-01-01T08:59:00Z', + updated_at: '2022-01-01T08:59:00Z', state: 'failure' }, { - created_at: '2022-01-01T08:00:00Z', + updated_at: '2022-01-01T08:00:00Z', state: 'success' } ] @@ -96,11 +96,11 @@ describe('removePrFromMergeQueue', () => { (octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({ data: [ { - created_at: '2022-01-01T09:01:00Z', + updated_at: '2022-01-01T09:01:00Z', state: 'failure' }, { - created_at: '2022-01-01T10:00:00Z', + updated_at: '2022-01-01T10:00:00Z', state: 'success' } ] @@ -133,15 +133,15 @@ describe('removePrFromMergeQueue', () => { (octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({ data: [ { - created_at: '2022-01-01T10:00:00Z', + updated_at: '2022-01-01T10:00:00Z', state: 'failure' }, { - created_at: '2022-01-01T09:01:00Z', + updated_at: '2022-01-01T09:01:00Z', state: 'pending' }, { - created_at: '2022-01-01T10:00:00Z', + updated_at: '2022-01-01T10:00:00Z', state: 'success' } ]