Skip to content

Commit

Permalink
changlogger: When amending, do not preserve default link
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`.
  • Loading branch information
anomiex committed Oct 22, 2024
1 parent 248684d commit 27a6229
Show file tree
Hide file tree
Showing 3 changed files with 57 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

0 comments on commit 27a6229

Please sign in to comment.