From d64ce006f03a2f45b34407831a1ae8f0d398ec8f Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 17 Jul 2023 10:18:55 +1000 Subject: [PATCH 1/4] Sorting found PRs by closed date in ascending order, from the oldest closed PRs to most recently closed PRs. --- bin/cherry-pick.mjs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/cherry-pick.mjs b/bin/cherry-pick.mjs index 36829db6ee5cf8..cf62c248797bbc 100644 --- a/bin/cherry-pick.mjs +++ b/bin/cherry-pick.mjs @@ -114,12 +114,15 @@ async function fetchPRs() { const { items } = await GitHubFetch( `/search/issues?q=is:pr state:closed sort:updated label:"${ LABEL }" repo:WordPress/gutenberg` ); - const PRs = items.map( ( { id, number, title } ) => ( { + const PRs = items.map( ( { id, number, title, updated_at, closed_at } ) => ( { id, number, title, - } ) ); - console.log( 'Found the following PRs to cherry-pick: ' ); + closed_at, + } ) ) + .sort( ( a, b ) => new Date( a.closed_at ) - new Date( b.closed_at ) ); + + console.log( 'Found the following PRs to cherry-pick (sorted by closed date in ascending order): ' ); PRs.forEach( ( { number, title } ) => console.log( indent( `#${ number } – ${ title }` ) ) ); From e5879a9e017ed2c84bb2d0a60ca339bdb56ca52c Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 17 Jul 2023 10:41:47 +1000 Subject: [PATCH 2/4] Now checking pull_request?.merged_at --- bin/cherry-pick.mjs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/cherry-pick.mjs b/bin/cherry-pick.mjs index cf62c248797bbc..4618fc7c9d995e 100644 --- a/bin/cherry-pick.mjs +++ b/bin/cherry-pick.mjs @@ -114,13 +114,22 @@ async function fetchPRs() { const { items } = await GitHubFetch( `/search/issues?q=is:pr state:closed sort:updated label:"${ LABEL }" repo:WordPress/gutenberg` ); - const PRs = items.map( ( { id, number, title, updated_at, closed_at } ) => ( { + const PRs = items.map( ( { id, number, title, pull_request, closed_at } ) => ( { id, number, title, closed_at, } ) ) - .sort( ( a, b ) => new Date( a.closed_at ) - new Date( b.closed_at ) ); + .sort( ( a, b ) => { + /* + * `closed_at` and `pull_request.merged_at` are _usually_ the same, + * but let's prefer the latter if it's available. + */ + if ( a?.pull_request?.merged_at && b?.pull_request?.merged_at ) { + return new Date( a?.pull_request?.merged_at ) - new Date( b?.pull_request?.merged_at ); + } + return new Date( a.closed_at ) - new Date( b.closed_at ); + } ); console.log( 'Found the following PRs to cherry-pick (sorted by closed date in ascending order): ' ); PRs.forEach( ( { number, title } ) => From ff0b0d2cc19020214e53d305f185154641af1b4d Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 17 Jul 2023 11:34:37 +1000 Subject: [PATCH 3/4] Now checking pull_request?.merged_at --- bin/cherry-pick.mjs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bin/cherry-pick.mjs b/bin/cherry-pick.mjs index 4618fc7c9d995e..f9ad2f4f051cf9 100644 --- a/bin/cherry-pick.mjs +++ b/bin/cherry-pick.mjs @@ -119,17 +119,18 @@ async function fetchPRs() { number, title, closed_at, - } ) ) - .sort( ( a, b ) => { - /* - * `closed_at` and `pull_request.merged_at` are _usually_ the same, - * but let's prefer the latter if it's available. - */ - if ( a?.pull_request?.merged_at && b?.pull_request?.merged_at ) { - return new Date( a?.pull_request?.merged_at ) - new Date( b?.pull_request?.merged_at ); - } - return new Date( a.closed_at ) - new Date( b.closed_at ); - } ); + pull_request, + } ) ).sort( ( a, b ) => { + /* + * `closed_at` and `pull_request.merged_at` are _usually_ the same, + * but let's prefer the latter if it's available. + */ + if ( a?.pull_request?.merged_at && b?.pull_request?.merged_at ) { + return new Date( a?.pull_request?.merged_at ) - new Date( b?.pull_request?.merged_at ); + } + return new Date( a.closed_at ) - new Date( b.closed_at ); + } ) + console.log( 'Found the following PRs to cherry-pick (sorted by closed date in ascending order): ' ); PRs.forEach( ( { number, title } ) => From a499154a7fd189eb81a2c10c3f38af4c4ad3a752 Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 17 Jul 2023 11:34:56 +1000 Subject: [PATCH 4/4] semi colon --- bin/cherry-pick.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cherry-pick.mjs b/bin/cherry-pick.mjs index f9ad2f4f051cf9..baf8d42962f8e8 100644 --- a/bin/cherry-pick.mjs +++ b/bin/cherry-pick.mjs @@ -129,7 +129,7 @@ async function fetchPRs() { return new Date( a?.pull_request?.merged_at ) - new Date( b?.pull_request?.merged_at ); } return new Date( a.closed_at ) - new Date( b.closed_at ); - } ) + } ); console.log( 'Found the following PRs to cherry-pick (sorted by closed date in ascending order): ' );