From 50e40f5f5c7d3a8251d81977ac312df86210bebc Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 18 Aug 2022 10:33:26 +0200 Subject: [PATCH 01/12] Backports script i1 --- bin/backports.mjs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 bin/backports.mjs diff --git a/bin/backports.mjs b/bin/backports.mjs new file mode 100644 index 00000000000000..3cb556ab7397fc --- /dev/null +++ b/bin/backports.mjs @@ -0,0 +1,50 @@ +/** + * External dependencies + */ +import Diff from 'diff'; +import SimpleGit from 'simple-git'; +import { dirname } from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = dirname( fileURLToPath( import.meta.url ) ); + +const simpleGit = SimpleGit( dirname( __dirname ) ); + +async function getCommits( file ) { + const options = { + file, + }; + const log = await simpleGit.log( options ); + return log.all; +} + +function matchFilename( file ) { + if ( file.startsWith( 'lib/compat/wordpress-6.1/' ) ) { + return file.replace( 'lib/compat/wordpress-6.1/', 'src/wp-includes/' ); + } + return file; +} + +const log = await getCommits( 'lib/compat/wordpress-6.1/' ); + +const prRegex = /\(#([0-9]+)\)$/; +const prs = log.map( ( { message } ) => message.match( prRegex )?.[ 1 ] ); +console.log( prs ); + +const hash = log[ 1 ].hash; + +const diff = await simpleGit.show( hash ); + +//console.log( diff ); + +const parsedDiff = Diff.parsePatch( diff ); + +//console.log( parsedDiff[ 0 ] ); + +const fileName = parsedDiff[ 0 ].oldFileName.replace( /a\//, '' ); + +console.log( matchFilename( fileName ) ); + +parsedDiff[ 0 ].newFileName = 'b/../wordpress-develop/' + matchFilename( fileName ); + +console.log( parsedDiff ); From c074317b456e2c1fbda6777eefe5fea3b4bf389d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 19 Aug 2022 17:53:12 +0200 Subject: [PATCH 02/12] Stop this silly diffing business --- bin/backports.mjs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index 3cb556ab7397fc..cbe8d3818661ec 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -1,7 +1,6 @@ /** * External dependencies */ -import Diff from 'diff'; import SimpleGit from 'simple-git'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -18,33 +17,10 @@ async function getCommits( file ) { return log.all; } -function matchFilename( file ) { - if ( file.startsWith( 'lib/compat/wordpress-6.1/' ) ) { - return file.replace( 'lib/compat/wordpress-6.1/', 'src/wp-includes/' ); - } - return file; -} - const log = await getCommits( 'lib/compat/wordpress-6.1/' ); const prRegex = /\(#([0-9]+)\)$/; const prs = log.map( ( { message } ) => message.match( prRegex )?.[ 1 ] ); console.log( prs ); -const hash = log[ 1 ].hash; - -const diff = await simpleGit.show( hash ); - -//console.log( diff ); - -const parsedDiff = Diff.parsePatch( diff ); - -//console.log( parsedDiff[ 0 ] ); - -const fileName = parsedDiff[ 0 ].oldFileName.replace( /a\//, '' ); - -console.log( matchFilename( fileName ) ); - -parsedDiff[ 0 ].newFileName = 'b/../wordpress-develop/' + matchFilename( fileName ); -console.log( parsedDiff ); From 1d6d0ba6a35ad34a79fda6ae6109dcfb785214f7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Aug 2022 14:07:47 +0200 Subject: [PATCH 03/12] List PRs per file --- bin/backports.mjs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index cbe8d3818661ec..56919589451b61 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -2,8 +2,9 @@ * External dependencies */ import SimpleGit from 'simple-git'; -import { dirname } from 'path'; +import { dirname, join as pathJoin } from 'path'; import { fileURLToPath } from 'url'; +import { promises as fsPromises } from 'fs'; const __dirname = dirname( fileURLToPath( import.meta.url ) ); @@ -17,10 +18,28 @@ async function getCommits( file ) { return log.all; } -const log = await getCommits( 'lib/compat/wordpress-6.1/' ); - const prRegex = /\(#([0-9]+)\)$/; -const prs = log.map( ( { message } ) => message.match( prRegex )?.[ 1 ] ); -console.log( prs ); +const ghRoot = 'https://github.com/WordPress/gutenberg/commits/trunk/'; +const backportDirectories = [ 'lib/compat/wordpress-6.1/' ]; + +backportDirectories.forEach( async ( backportDir ) => { + console.log( `### ${ backportDir }\n` ); + const files = await fsPromises.readdir( backportDir ); + for ( const file of files ) { + const path = pathJoin( backportDir, file ); + const stat = await fsPromises.stat( path ); + if ( ! stat.isFile() ) { + continue; + } + console.log( `- ${ file }` ); + const log = await getCommits( path ); + const prs = log.map( + ( { message } ) => message.match( prRegex )?.[ 1 ] + ); + prs.forEach( ( pr ) => { + console.log( ` - #${ pr }` ); + } ); + } +} ); From 2eb4ebeea0f92f1e778eeb1bdd6ef312ff5dcf5d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Aug 2022 14:09:08 +0200 Subject: [PATCH 04/12] Include lib/block-supports --- bin/backports.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index 56919589451b61..91542de875bd32 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -20,7 +20,10 @@ async function getCommits( file ) { const prRegex = /\(#([0-9]+)\)$/; const ghRoot = 'https://github.com/WordPress/gutenberg/commits/trunk/'; -const backportDirectories = [ 'lib/compat/wordpress-6.1/' ]; +const backportDirectories = [ + 'lib/block-supports/', + 'lib/compat/wordpress-6.1/', +]; backportDirectories.forEach( async ( backportDir ) => { console.log( `### ${ backportDir }\n` ); From bae3ab36a9f753215dccee5bbc03e35eb643b6c9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Aug 2022 14:13:17 +0200 Subject: [PATCH 05/12] Add links to file commit histories --- bin/backports.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index 91542de875bd32..4bbded3fa5833d 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -35,7 +35,7 @@ backportDirectories.forEach( async ( backportDir ) => { continue; } - console.log( `- ${ file }` ); + console.log( `- [${ file }](${ ghRoot }${ path })` ); const log = await getCommits( path ); const prs = log.map( From a8a7e80fafa4859e97564f9d8c2654ff77c17480 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Aug 2022 23:19:42 +0200 Subject: [PATCH 06/12] List authors --- bin/backports.mjs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index 4bbded3fa5833d..3355518e67c3ca 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -5,11 +5,14 @@ import SimpleGit from 'simple-git'; import { dirname, join as pathJoin } from 'path'; import { fileURLToPath } from 'url'; import { promises as fsPromises } from 'fs'; +import { Octokit } from '@octokit/rest'; const __dirname = dirname( fileURLToPath( import.meta.url ) ); const simpleGit = SimpleGit( dirname( __dirname ) ); +const octokit = new Octokit(); + async function getCommits( file ) { const options = { file, @@ -25,7 +28,7 @@ const backportDirectories = [ 'lib/compat/wordpress-6.1/', ]; -backportDirectories.forEach( async ( backportDir ) => { +for ( const backportDir of backportDirectories ) { console.log( `### ${ backportDir }\n` ); const files = await fsPromises.readdir( backportDir ); for ( const file of files ) { @@ -38,11 +41,27 @@ backportDirectories.forEach( async ( backportDir ) => { console.log( `- [${ file }](${ ghRoot }${ path })` ); const log = await getCommits( path ); - const prs = log.map( + const prNumbers = log.map( ( { message } ) => message.match( prRegex )?.[ 1 ] ); - prs.forEach( ( pr ) => { - console.log( ` - #${ pr }` ); - } ); + + const authors = new Set(); + for ( const prNumber of prNumbers ) { + if ( ! prNumber ) { + continue; + } + const pr = await octokit.pulls.get( { + owner: 'WordPress', + repo: 'gutenberg', + pull_number: prNumber, + } ); + authors.add( pr.data.user.login ); + console.log( ` - #${ prNumber }` ); + } + + const byline = [ ...authors ] + .map( ( author ) => `@${ author }` ) + .join( ' ' ); + console.log( byline ); } -} ); +} From 28929b03c0584174941687c2e7a459f3360e6a65 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 26 Aug 2022 13:37:15 +0200 Subject: [PATCH 07/12] Fix import (version mismatch) --- bin/backports.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index 3355518e67c3ca..5a24269d874fe3 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -5,7 +5,7 @@ import SimpleGit from 'simple-git'; import { dirname, join as pathJoin } from 'path'; import { fileURLToPath } from 'url'; import { promises as fsPromises } from 'fs'; -import { Octokit } from '@octokit/rest'; +import Octokit from '@octokit/rest'; const __dirname = dirname( fileURLToPath( import.meta.url ) ); From 71f49f47ec82151c3726d6c3fdf69695b302485e Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 26 Aug 2022 14:37:39 +0200 Subject: [PATCH 08/12] More links --- bin/backports.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index 5a24269d874fe3..56ce7042de93cf 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -22,14 +22,15 @@ async function getCommits( file ) { } const prRegex = /\(#([0-9]+)\)$/; -const ghRoot = 'https://github.com/WordPress/gutenberg/commits/trunk/'; +const ghTreeRoot = 'https://github.com/WordPress/gutenberg/tree/trunk/'; +const ghCommitsRoot = 'https://github.com/WordPress/gutenberg/commits/trunk/'; const backportDirectories = [ 'lib/block-supports/', 'lib/compat/wordpress-6.1/', ]; for ( const backportDir of backportDirectories ) { - console.log( `### ${ backportDir }\n` ); + console.log( `### [${ backportDir }](${ ghTreeRoot }${ backportDir })\n` ); const files = await fsPromises.readdir( backportDir ); for ( const file of files ) { const path = pathJoin( backportDir, file ); @@ -38,7 +39,7 @@ for ( const backportDir of backportDirectories ) { continue; } - console.log( `- [${ file }](${ ghRoot }${ path })` ); + console.log( `- [${ file }](${ ghCommitsRoot }${ path })` ); const log = await getCommits( path ); const prNumbers = log.map( From 9ff935b0e1e296969c22320ada769c884d339500 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 26 Aug 2022 14:56:08 +0200 Subject: [PATCH 09/12] Specify commits range --- bin/backports.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/backports.mjs b/bin/backports.mjs index 56ce7042de93cf..ba12287489bd29 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -16,6 +16,8 @@ const octokit = new Octokit(); async function getCommits( file ) { const options = { file, + from: 'wp/6.0', + to: 'HEAD', }; const log = await simpleGit.log( options ); return log.all; From 1944f6b0ae702d4af05c5dce0a6e5aac7571d098 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 26 Aug 2022 15:06:44 +0200 Subject: [PATCH 10/12] Add getPreviousMajorVersion --- bin/plugin/lib/test/version.js | 18 ++++++++++++++++-- bin/plugin/lib/version.js | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bin/plugin/lib/test/version.js b/bin/plugin/lib/test/version.js index b38875ccb72c04..2a5e226836583f 100644 --- a/bin/plugin/lib/test/version.js +++ b/bin/plugin/lib/test/version.js @@ -1,10 +1,10 @@ /** * Internal dependencies */ -import { getNextMajorVersion } from '../version'; +import { getNextMajorVersion, getPreviousMajorVersion } from '../version'; describe( 'getNextMajorVersion', () => { - it( 'increases the minor number by default', () => { + it( 'increments the minor number by default', () => { const result = getNextMajorVersion( '7.3.4-rc.1' ); expect( result ).toBe( '7.4.0' ); @@ -16,3 +16,17 @@ describe( 'getNextMajorVersion', () => { expect( result ).toBe( '8.0.0' ); } ); } ); + +describe( 'getPreviousMajorVersion', () => { + it( 'decrements the minor number by default', () => { + const result = getPreviousMajorVersion( '7.4.0' ); + + expect( result ).toBe( '7.3.0' ); + } ); + + it( 'follows the WordPress versioning scheme', () => { + const result = getPreviousMajorVersion( '8.0.0' ); + + expect( result ).toBe( '7.9.0' ); + } ); +} ); diff --git a/bin/plugin/lib/version.js b/bin/plugin/lib/version.js index 64fefdb7ff8107..83cd730759fbfc 100644 --- a/bin/plugin/lib/version.js +++ b/bin/plugin/lib/version.js @@ -4,7 +4,7 @@ /** * Follow the WordPress version guidelines to compute - * the version to be used By default, increase the "minor" + * the version to be used By default, increment the "minor" * number but if we reach 9, bump to the next major. * * @param {string} version Current version. @@ -18,6 +18,23 @@ function getNextMajorVersion( version ) { return major + '.' + ( minor + 1 ) + '.0'; } +/** + * Follow the WordPress version guidelines to compute + * the version to be used. By default, decrement the "minor" + * number but if we reach 0, decrease to the next major. + * + * @param {string} version Current version. + * @return {string} Previous Major Version. + */ +function getPreviousMajorVersion( version ) { + const [ major, minor ] = version.split( '.' ).map( Number ); + if ( minor === 0 ) { + return major - 1 + '.9.0'; + } + return major + '.' + ( minor - 1 ) + '.0'; +} + module.exports = { getNextMajorVersion, + getPreviousMajorVersion, }; From c67c97b96f01e0131d1f1adc7823342b62b7c9f8 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 26 Aug 2022 15:11:08 +0200 Subject: [PATCH 11/12] Compute previous WP version automatically --- bin/backports.mjs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/backports.mjs b/bin/backports.mjs index ba12287489bd29..ddc967239337cf 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -7,16 +7,26 @@ import { fileURLToPath } from 'url'; import { promises as fsPromises } from 'fs'; import Octokit from '@octokit/rest'; +/** + * Internal dependencies + */ +import { getPreviousMajorVersion } from './plugin/lib/version.js'; + const __dirname = dirname( fileURLToPath( import.meta.url ) ); const simpleGit = SimpleGit( dirname( __dirname ) ); - const octokit = new Octokit(); +const wpVersion = '6.1'; +const previousWpVersion = getPreviousMajorVersion( wpVersion ).replace( + /\.0$/, + '' +); + async function getCommits( file ) { const options = { file, - from: 'wp/6.0', + from: `wp/${ previousWpVersion }`, to: 'HEAD', }; const log = await simpleGit.log( options ); @@ -28,7 +38,7 @@ const ghTreeRoot = 'https://github.com/WordPress/gutenberg/tree/trunk/'; const ghCommitsRoot = 'https://github.com/WordPress/gutenberg/commits/trunk/'; const backportDirectories = [ 'lib/block-supports/', - 'lib/compat/wordpress-6.1/', + `lib/compat/wordpress-${ wpVersion }/`, ]; for ( const backportDir of backportDirectories ) { From fa767421580c96a5ed70ebe477194d43039722ea Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 26 Aug 2022 15:57:09 +0200 Subject: [PATCH 12/12] Include lib/experimental/ dir --- bin/backports.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/backports.mjs b/bin/backports.mjs index ddc967239337cf..9bfc2c05d127d7 100644 --- a/bin/backports.mjs +++ b/bin/backports.mjs @@ -39,6 +39,7 @@ const ghCommitsRoot = 'https://github.com/WordPress/gutenberg/commits/trunk/'; const backportDirectories = [ 'lib/block-supports/', `lib/compat/wordpress-${ wpVersion }/`, + 'lib/experimental/', ]; for ( const backportDir of backportDirectories ) {