Skip to content

Commit

Permalink
Backport tools: sort PRs to be cherry picked by merged/closed date (#…
Browse files Browse the repository at this point in the history
…52667)

* Sorting found PRs by closed date in ascending order, from the oldest closed PRs to most recently closed PRs.

* Now checking pull_request?.merged_at

* Now checking pull_request?.merged_at

* semi colon
  • Loading branch information
ramonjd committed Jul 17, 2023
1 parent 5a52ea1 commit 4f4b5a1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bin/cherry-pick.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,25 @@ 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, pull_request, closed_at } ) => ( {
id,
number,
title,
} ) );
console.log( 'Found the following PRs to cherry-pick: ' );
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 } ) =>
console.log( indent( `#${ number }${ title }` ) )
);
Expand Down

0 comments on commit 4f4b5a1

Please sign in to comment.