Skip to content

Commit 6ac3ce8

Browse files
authored
cli: Add jetpack changelog add --base-ref (#42583)
By default `jetpack changelog add` compares with `origin/trunk` to determine what projects need changelog entries. If you're working on a PR that's a followup to another, though, you might want it to compare with that base PR's branch instead.
1 parent c07dcaf commit 6ac3ce8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tools/cli/commands/changelog.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export function changelogDefine( yargs ) {
8181
describe:
8282
'Never ask whether affected plugins without direct changes should have change entries added.',
8383
type: 'boolean',
84+
} )
85+
.option( 'base-ref', {
86+
describe: 'Git ref to compare to.',
87+
type: 'string',
88+
default: 'origin/trunk',
8489
} );
8590
},
8691
async argv => {
@@ -321,7 +326,7 @@ async function changelogAdd( argv ) {
321326

322327
// If we weren't passed a project, check if any projects need changelogs.
323328
if ( argv._[ 1 ] === 'add' && ! argv.project ) {
324-
changelogInfo = await checkChangelogFiles();
329+
changelogInfo = await checkChangelogFiles( argv.baseRef );
325330
needChangelog = changelogInfo.need;
326331
}
327332
if ( needChangelog.length === 0 ) {
@@ -336,7 +341,7 @@ async function changelogAdd( argv ) {
336341
}
337342

338343
if ( argv.checkIndirectPlugins ?? needChangelog.length > 0 ) {
339-
changelogInfo ??= await checkChangelogFiles();
344+
changelogInfo ??= await checkChangelogFiles( argv.baseRef );
340345
await addIndirectPlugins(
341346
argv,
342347
argv.checkIndirectPlugins ? changelogInfo.touched : needChangelog,
@@ -531,6 +536,8 @@ async function changelogArgs( argv ) {
531536
...projectTypes,
532537
'--check-indirect-plugins',
533538
'--no-check-indirect-plugins',
539+
'--base-ref',
540+
'--base-ref=' + argv.baseRef,
534541
];
535542
let file;
536543

@@ -682,12 +689,13 @@ async function gitAdd( argv ) {
682689
/**
683690
* Checks if changelog files are required.
684691
*
692+
* @param {string} baseRef - Git reference to compare with.
685693
* @return {object} as follows:
686694
* - {string[]} touched - Touched projects.
687695
* - {Map<string,string[]>} files - Change files by project.
688696
* - {string[]} need - Projects needing changelogs.
689697
*/
690-
async function checkChangelogFiles() {
698+
async function checkChangelogFiles( baseRef ) {
691699
console.log( chalk.green( 'Checking if changelog files are needed. Just a sec...' ) );
692700

693701
// Bail if we're pushing to a release branch, like boost/branch-1.3.0
@@ -714,7 +722,7 @@ async function checkChangelogFiles() {
714722
`--no-renames`,
715723
`--name-only`,
716724
`--merge-base`,
717-
`origin/trunk`,
725+
baseRef,
718726
] );
719727
touchedFiles = touchedFiles.stdout.toString().trim().split( '\n' );
720728

0 commit comments

Comments
 (0)