Skip to content

fix(changelog): keep the case of titles when reading the changelog - #2137

Open
vinilpolepalli wants to merge 1 commit into
commitizen-tools:masterfrom
vinilpolepalli:fix-changelog-tag-format-case
Open

vinilpolepalli wants to merge 1 commit into
commitizen-tools:masterfrom
vinilpolepalli:fix-changelog-tag-format-case

Conversation

@vinilpolepalli

Copy link
Copy Markdown

Description

The changelog formats read the existing changelog in lower case before they match titles against tag_format. The tag_format regexes are case-sensitive. When tag_format contains an uppercase character (for example Release-$version or V$version), the latest release title does not match. The incremental changelog then does not find the latest version and writes all versions again, so the changelog gets duplicate entries.

This change keeps the original case of each line in BaseFormat.get_metadata_from_file, BaseFormat.get_latest_full_release_from_file and RestructuredText.get_metadata_from_file. Only the "unreleased" check stays case-insensitive.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

Assisted By: AI

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests (ran poe format, poe lint and poe test separately; only the GPG tests fail locally because gpg is not installed, same as on master)
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes (not needed, bug fix only)

Expected Behavior

With tag_format = "Release-$version", each cz bump --changelog adds only the new version at the top of the changelog. Before this fix, the second bump wrote Release-1.1.1 and Release-1.1.0 again below the existing Release-1.1.0 entry.

Steps to Test This Pull Request

  1. git init a new repository and add .cz.toml:
    [tool.commitizen]
    version = "1.0.0"
    tag_format = "Release-$version"
    update_changelog_on_bump = true
  2. Commit feat: a and run cz bump --yes.
  3. Commit fix: b and run cz bump --yes.
  4. CHANGELOG.md must contain ## Release-1.1.1 then ## Release-1.1.0, each one time.

New tests: a Release-${version} case in test_get_metadata_custom_tag_format for all four formats, and test_changelog_incremental_with_uppercase_tag_format. They fail without the fix and pass with it.

Additional Context

Open PR #1596 refactors get_metadata_from_file and touches the same lines. It keeps .lower(), so it does not fix this issue.

🤖 Generated with Claude Code

The changelog formats read the existing changelog in lower case.
A `tag_format` with an uppercase character (e.g. `Release-$version`)
then does not match the latest release title. The incremental
changelog does not find the latest version and writes all versions
again, so the changelog gets duplicate entries.

Read the titles with their original case. Only the "unreleased"
check stays case-insensitive.

Assisted By: AI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (fb3d172) to head (11722e3).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2137   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files          61       61           
  Lines        2874     2874           
=======================================
  Hits         2825     2825           
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant