Skip to content

Commit

Permalink
changlogger: When amending, do not preserve default link (#39868)
Browse files Browse the repository at this point in the history
When doing `changelogger write --amend`, we normally preserve the
prologue, epilogue, and link unless these are overridden on the command
line.

An edge case is when you're amending version 1.2.3-beta to turn it into
1.2.3 release, and the link is the default link like
`https://example.com/diff/1.2.2...1.2.3-beta`. In this situation we
don't want to keep that link, we want to replace it with the new default
`https://example.com/diff/1.2.2...1.2.3`.

Also, when building changelogger, we have to install before trying to run it.
  • Loading branch information
anomiex authored Oct 23, 2024
1 parent 5927dd6 commit 07e18c2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

When amending, do not preserve a default link. We'll want the link to be updated to the new default.
6 changes: 5 additions & 1 deletion projects/packages/changelogger/src/WriteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ protected function doAmendChanges( InputInterface $input, OutputInterface $outpu
$input->setOption( 'epilogue', $latest->getEpilogue() );
}
if ( $input->getOption( 'link' ) === null ) {
$input->setOption( 'link', $latest->getLink() );
$oldLink = $latest->getLink();
$defaultLink = $changelog->getLatestEntry() ? Config::link( $changelog->getLatestEntry()->getVersion(), $latest->getVersion() ) : null;
if ( $oldLink !== $defaultLink ) {
$input->setOption( 'link', $latest->getLink() );
}
}
} else {
$output->writeln( 'No version to amend, ignoring --amend.', OutputInterface::VERBOSITY_DEBUG );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,54 @@ public function provideExecute() {
true,
"# Changelog\n\n## 1.0.1 - $date\n\nPrologue for v1.0.1\n\n### Added\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n",
),
'Amend, beta to release' => array(
array( '--amend' => true ),
array(
'composer.json' => array( 'link-template' => 'https://example.org/diff/${old}..${new}' ),
'changes' => array(),
'changelog' => "# Changelog\n\n## [1.0.1-beta] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1-beta]: https://example.org/new-link\n",
),
array( 'Y' ),
0,
array(
'{^No changes were found! Proceed\? \[y/N\] $}m',
),
true,
"# Changelog\n\n## [1.0.1] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1]: https://example.org/new-link\n",
),
'Amend, ignore default link' => array(
array( '--amend' => true ),
array(
'composer.json' => array( 'link-template' => 'https://example.org/diff/${old}..${new}' ),
'changes' => array(),
'changelog' => "# Changelog\n\n## [1.0.1-beta] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1-beta]: https://example.org/diff/1.0.0..1.0.1-beta\n",
),
array( 'Y' ),
0,
array(
'{^No changes were found! Proceed\? \[y/N\] $}m',
),
true,
"# Changelog\n\n## [1.0.1] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1]: https://example.org/diff/1.0.0..1.0.1\n",
),
'Amend, manually override default link' => array(
array(
'--amend' => true,
'--link' => 'https://example.org/new-link',
),
array(
'composer.json' => array( 'link-template' => 'https://example.org/diff/${old}..${new}' ),
'changes' => array(),
'changelog' => "# Changelog\n\n## [1.0.1-beta] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1-beta]: https://example.org/diff/1.0.0..1.0.1-beta\n",
),
array( 'Y' ),
0,
array(
'{^No changes were found! Proceed\? \[y/N\] $}m',
),
true,
"# Changelog\n\n## [1.0.1] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1]: https://example.org/new-link\n",
),

'--use-version invalid' => array(
array( '--use-version' => '2.0' ),
Expand Down
9 changes: 9 additions & 0 deletions tools/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,15 @@ async function buildProject( t ) {
() => false
)
) {
// If we're building changelogger itself, we need to install before we can run it.
if ( t.project === 'packages/changelogger' ) {
await t.execa( 'composer', await getInstallArgs( t.project, 'composer', t.argv ), {
cwd: t.cwd,
stdio: [ 'ignore', 'inherit', 'inherit' ],
buffer: false,
} );
}

let prerelease = 'alpha';
if ( composerJson.extra?.[ 'dev-releases' ] ) {
const m = (
Expand Down

0 comments on commit 07e18c2

Please sign in to comment.