From 178cc994bc57aa02f2f03cb1bb9c70795b622cc0 Mon Sep 17 00:00:00 2001 From: Sam SIU <23556929+ssiuhk@users.noreply.github.com> Date: Sun, 21 Aug 2022 23:54:07 +0000 Subject: [PATCH] fix(command_changelog): Fixed issue #561 cz bump could not find the latest version tag with custom tag_format - Updated args to _find_incremental_rev to use latest_tag_version instead of latest_version - Updated test case for test_changelog_command.py from .next to .rc as python packaging lib doesn't take 'next' as a valid version --- commitizen/commands/changelog.py | 7 +++++-- tests/commands/test_changelog_command.py | 4 ++-- .../test_changelog_incremental_angular_sample.md | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 0520b95257..854060a867 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -3,7 +3,7 @@ from operator import itemgetter from typing import Callable, Dict, List, Optional -from commitizen import changelog, defaults, factory, git, out +from commitizen import bump, changelog, defaults, factory, git, out from commitizen.config import BaseConfig from commitizen.exceptions import ( DryRunExit, @@ -132,7 +132,10 @@ def __call__(self): changelog_meta = changelog.get_metadata(self.file_name) latest_version = changelog_meta.get("latest_version") if latest_version: - start_rev = self._find_incremental_rev(latest_version, tags) + latest_tag_version: str = bump.normalize_tag( + latest_version, tag_format=self.tag_format + ) + start_rev = self._find_incremental_rev(latest_tag_version, tags) if self.rev_range and self.tag_format: start_rev, end_rev = changelog.get_oldest_and_newest_rev( diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index 030d53824d..dc932bd405 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -142,14 +142,14 @@ def test_changelog_incremental_angular_sample( ): with open(changelog_path, "w") as f: f.write( - "# [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)\n" + "# [10.0.0-rc.3](https://github.com/angular/angular/compare/10.0.0-rc.2...10.0.0-rc.3) (2020-04-22)\n" "\n" "### Bug Fixes" "\n" "* **common:** format day-periods that cross midnight ([#36611](https://github.com/angular/angular/issues/36611)) ([c6e5fc4](https://github.com/angular/angular/commit/c6e5fc4)), closes [#36566](https://github.com/angular/angular/issues/36566)\n" ) create_file_and_commit("irrelevant commit") - git.tag("10.0.0-next.3") + git.tag("10.0.0-rc.3") create_file_and_commit("feat: add new output") create_file_and_commit("fix: output glitch") diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_angular_sample.md b/tests/commands/test_changelog_command/test_changelog_incremental_angular_sample.md index ea4c57c974..83bfdfe852 100644 --- a/tests/commands/test_changelog_command/test_changelog_incremental_angular_sample.md +++ b/tests/commands/test_changelog_command/test_changelog_incremental_angular_sample.md @@ -10,7 +10,7 @@ - mama gotta work - output glitch -# [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22) +# [10.0.0-rc.3](https://github.com/angular/angular/compare/10.0.0-rc.2...10.0.0-rc.3) (2020-04-22) ### Bug Fixes * **common:** format day-periods that cross midnight ([#36611](https://github.com/angular/angular/issues/36611)) ([c6e5fc4](https://github.com/angular/angular/commit/c6e5fc4)), closes [#36566](https://github.com/angular/angular/issues/36566)