Skip to content

Commit

Permalink
WIP investigating tag formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamhar committed Mar 26, 2024
1 parent c89218b commit fcfd4dc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
9 changes: 7 additions & 2 deletions commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from typing import Callable

from commitizen import changelog, defaults, factory, git, out
from commitizen import bump, changelog, defaults, factory, git, out

from commitizen.config import BaseConfig
from commitizen.cz.base import MessageBuilderHook, ChangelogReleaseHook
Expand Down Expand Up @@ -177,8 +177,13 @@ def __call__(self):
if self.incremental:
changelog_meta = self.changelog_format.get_metadata(self.file_name)
if changelog_meta.latest_version:
latest_tag_version: str = bump.normalize_tag(
changelog_meta.latest_version,
tag_format=self.tag_format,
scheme=self.scheme,
)
start_rev = self._find_incremental_rev(
strip_local_version(changelog_meta.latest_version), tags
strip_local_version(latest_tag_version), tags
)
if self.rev_range:
start_rev, end_rev = changelog.get_oldest_and_newest_rev(
Expand Down
40 changes: 39 additions & 1 deletion tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,9 +1540,47 @@ def test_changelog_only_tag_matching_tag_format_included(
mocker.patch.object(sys, "argv", testargs)
cli.main()
wait_for_tag()
create_file_and_commit("feat: some awesome new feature")
# git.tag("0.2.1")
testargs = ["cz", "bump", "--changelog", "--yes"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
wait_for_tag()
with open(changelog_path) as f:
out = f.read()
assert out.startswith("## 0.3.0custom (2021-06-11)")
assert "## 0.2.0custom (2021-06-11)" in out
assert "## v0.2.0 (2021-06-11)" not in out
assert "## 0.2.0 (2021-06-11)" not in out


@pytest.mark.usefixtures("tmp_commitizen_project")
@pytest.mark.freeze_time("2021-06-11")
def test_changelog_only_tag_matching_tag_format_included_prefix(
mocker: MockFixture,
changelog_path: Path,
config_path: Path,
):
with open(config_path, "a", encoding="utf-8") as f:
f.write('\ntag_format = "example-${version}"\n')
create_file_and_commit("feat: new file")
git.tag("v0.2.0")
create_file_and_commit("feat: another new file")
git.tag("0.2.0")
git.tag("random0.2.0")
testargs = ["cz", "bump", "--changelog", "--yes"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
wait_for_tag()
create_file_and_commit("feat: some awesome new feature")
testargs = ["cz", "bump", "--changelog", "--yes"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
wait_for_tag()
with open(changelog_path) as f:
out = f.read()
assert out.startswith("## 0.2.0custom (2021-06-11)")
assert out.startswith("## example-0.3.0 (2021-06-11)")
assert "## example-0.2.0 (2021-06-11)" in out
assert "## v0.2.0 (2021-06-11)" not in out
assert "## 0.2.0 (2021-06-11)" not in out

Expand Down
32 changes: 32 additions & 0 deletions tests/test_changelog_format_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@
)


CHANGELOG_E = """
# Unreleased
## example-1.0.0
"""
EXPECTED_E = Metadata(
latest_version="1.0.0",
latest_version_position=3,
unreleased_end=3,
unreleased_start=1,
)


CHANGELOG_F = """
# Unreleased
## 1.0.0-custom
"""
EXPECTED_F = Metadata(
latest_version="1.0.0",
latest_version_position=3,
unreleased_end=3,
unreleased_start=1,
)


@pytest.fixture
def format(config: BaseConfig) -> Markdown:
return Markdown(config)
Expand All @@ -94,6 +120,10 @@ def format(config: BaseConfig) -> Markdown:
("All notable changes to this project will be documented in this file.", None),
("# Changelog", None),
("### Bug Fixes", None),
("### 0.1.1custom", "0.1.1"),
("### 0.1.1-custom", "0.1.1"),
("### example0.1.1", "0.1.1"),
("### example-0.1.1", "0.1.1"),
]


Expand Down Expand Up @@ -127,6 +157,8 @@ def test_parse_title_type_of_line(
pytest.param(CHANGELOG_B, EXPECTED_B, id="B"),
pytest.param(CHANGELOG_C, EXPECTED_C, id="C"),
pytest.param(CHANGELOG_D, EXPECTED_D, id="D"),
pytest.param(CHANGELOG_E, EXPECTED_E, id="E"),
pytest.param(CHANGELOG_F, EXPECTED_F, id="F"),
),
)
def test_get_matadata(
Expand Down

0 comments on commit fcfd4dc

Please sign in to comment.