Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions commitizen/changelog_formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
meta = Metadata()
unreleased_level: int | None = None
for index, line in enumerate(file):
line = line.strip().lower()
# Keep the original case: `tag_format` can contain uppercase characters.
line = line.strip()

unreleased: int | None = None
if "unreleased" in line:
if "unreleased" in line.lower():
unreleased = self.parse_title_level(line)
# Try to find beginning and end lines of the unreleased block
if unreleased:
Expand Down Expand Up @@ -84,7 +85,7 @@ def get_latest_full_release_from_file(self, file: IO[Any]) -> IncrementalMergeIn
latest_version_index: int | None = None
for index, line in enumerate(file):
latest_version_index = index
line = line.strip().lower()
line = line.strip()

parsed_version = self.parse_version_from_title(line)
if (
Expand Down
5 changes: 3 additions & 2 deletions commitizen/changelog_formats/restructuredtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def get_metadata_from_file(self, file: IO[str]) -> Metadata:
out_metadata = Metadata()
unreleased_title_kind: str | tuple[str, str] | None = None
is_overlined_title = False
lines = [line.strip().lower() for line in file.readlines()]
# Keep the original case: `tag_format` can contain uppercase characters.
lines = [line.strip() for line in file.readlines()]

for index, (first, second, third) in enumerate(
zip_longest(lines, lines[1:], lines[2:], fillvalue="")
Expand All @@ -44,7 +45,7 @@ def get_metadata_from_file(self, file: IO[str]) -> Metadata:
if not title:
continue

if "unreleased" in title:
if "unreleased" in title.lower():
unreleased_title_kind = kind
out_metadata.unreleased_start = index
continue
Expand Down
28 changes: 28 additions & 0 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,34 @@ def test_changelog_only_tag_matching_tag_format_included_suffix_sep(
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_incremental_with_uppercase_tag_format(
changelog_path: Path,
config_path: Path,
util: UtilFixture,
):
"""An uppercase character in `tag_format` must not break the incremental changelog.

Before the fix, the existing changelog was read in lower case, so the latest
release title did not match `tag_format` and all versions were written again.
"""
# Arrange
with config_path.open("a", encoding="utf-8") as f:
f.write('\ntag_format = "Release-${version}"\n')
util.create_file_and_commit("feat: new file")
util.run_cli("bump", "--changelog", "--yes")
util.create_file_and_commit("fix: some fix")

# Act
util.run_cli("bump", "--changelog", "--yes")

# Assert
out = changelog_path.read_text()
assert out.startswith("## Release-0.2.1 (2021-06-11)")
assert out.count("## Release-0.2.0 (2021-06-11)") == 1


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_changelog_legacy_tags(
changelog_path: Path,
Expand Down
1 change: 1 addition & 0 deletions tests/test_changelog_format_asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def test_get_latest_full_release_no_file(format: AsciiDoc):
"1.0.0-a1.dev1",
),
pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"),
pytest.param("Release-${version}", "Release-1.0.0", "1.0.0"),
],
indirect=["format_with_tags"],
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_changelog_format_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def test_get_metadata(
"1.0.0-a1.dev1",
),
pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"),
pytest.param("Release-${version}", "Release-1.0.0", "1.0.0"),
],
indirect=["format_with_tags"],
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_changelog_format_restructuredtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def test_is_overlined_title(text: str, expected: bool):
"1.0.0-a1.dev1",
),
pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"),
pytest.param("Release-${version}", "Release-1.0.0", "1.0.0"),
],
indirect=["format_with_tags"],
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_changelog_format_textile.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def test_get_metadata(
"1.0.0-a1.dev1",
),
pytest.param("new-${version}", "legacy-1.0.0", "1.0.0"),
pytest.param("Release-${version}", "Release-1.0.0", "1.0.0"),
],
indirect=["format_with_tags"],
)
Expand Down
Loading