Skip to content

feat(changelog): add changelog_use_bare_version setting - #2141

Open
pranjalbhatia710 wants to merge 1 commit into
commitizen-tools:masterfrom
pranjalbhatia710:fix/562-changelog-bare-version
Open

pranjalbhatia710 wants to merge 1 commit into
commitizen-tools:masterfrom
pranjalbhatia710:fix/562-changelog-bare-version

Conversation

@pranjalbhatia710

Copy link
Copy Markdown

The triage comment on #562 suggests an opt-in setting; this PR implements it. The setting can become the default instead if maintainers prefer that.

Description

Fixes #562

This adds the changelog_use_bare_version setting. When it is true, release titles in the changelog contain the version without the tag_format prefix and suffix: with tag_format = "v$version", the title is ## 1.0.0 instead of ## v1.0.0. The default is false, so existing changelogs do not change.

Root cause: generate_tree_from_commits in commitizen/changelog.py uses tag.name as the release title, so the tag_format prefix is always in the title.

Fix:

  • Write path: the release title comes from TagRules.extract_version(tag) (falls back to the tag name). This is the version as normalized by the version scheme, so a tag v1.0.0-rc1 under pep440 is titled 1.0.0rc1. cz bump --changelog passes the new version as the unreleased version.
  • Read path: the incremental changelog finds the latest release from its title. A bare title does not match tag_format, so the changelog formats also read bare titles when the setting is on. The git tag of the release is then found by its version (TagRules.find_tag_for), so tags in a legacy_tag_formats format are found too, also with changelog_merge_prerelease. Titles with the tag name still parse, so the setting can be enabled on an existing changelog. If a title contains both a bare version and a tag name (for example, a compare link), the first one is read (the last one in AsciiDoc, where link labels come last). A title whose version-like text is not a valid version for the version scheme is ignored, as it is with the setting off. Custom changelog formats that call self.tag_rules.search_version must call self.search_version to read bare titles. With the setting on, any title that contains a version (for example, ## Python 3.12.1 support) is read as a release title, as it already is with the default tag_format = "$version".
  • Docs: docs/config/changelog.md and docs/config/configuration_file.md.

The triage comment suggested changelog_use_bare_version or changelog_strip_tag_prefix. This uses the first name because suffixes ($version-custom) are removed too.

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
  • 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

uv run poe all was not run as one command. Tested on macOS arm64, Python 3.13:

  • ruff check, ruff format --check and mypy on commitizen and tests: clean.
  • cz check --rev-range origin/master..HEAD: valid.
  • Full pytest -n 4 tests: 1386 passed, 2 skipped, 2 xfailed.
  • pytest --cov=commitizen --cov-report=term-missing over the changelog, changelog format, bump and config test modules: no new line is reported as missing (re-run on the final commit: 542 passed, commitizen/changelog_formats/base.py at 100%).

New tests (34 cases: 22 fail on master, 8 of them because the tested functions are new; the other 12 pass on master because they check unchanged behaviour with the setting off or titles that master already reads correctly):

  • cz changelog with bare titles, repeated incremental cz bump --changelog, enabling the setting on a changelog with tag-name titles, a bare title whose release is tagged in a legacy format.
  • Prerelease merging, also with a legacy-format tag.
  • Title parsing in Markdown and AsciiDoc, including titles with both a bare version and a tag name in a compare link (Markdown reads the first version, AsciiDoc the last), a title with a version that is not valid for the version scheme, and get_metadata with a bare title in all four formats (Markdown, AsciiDoc, Textile, reStructuredText).
  • Unit tests for changelog.get_release_title (setting off, setting on, legacy-format tag, tag that matches no format) and Changelog._find_release_tag (setting off, legacy-format tag, no matching tag, no version).

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external)

Expected Behavior

With tag_format = "SOME_TAG_PREFIX_$version" and changelog_use_bare_version = true, cz changelog and cz bump --changelog write ## 1.1.0 (date) rather than ## SOME_TAG_PREFIX_1.1.0 (date), and later incremental runs do not duplicate releases. With the setting off, the output is unchanged.

Steps to Test This Pull Request

  1. In a new git repository, create pyproject.toml with:
    [tool.commitizen]
    version = "1.0.0"
    tag_format = "SOME_TAG_PREFIX_$version"
    update_changelog_on_bump = true
    changelog_use_bare_version = true
  2. Commit feat: initial, tag SOME_TAG_PREFIX_1.0.0, commit feat(Testing): Testing something.
  3. Run cz bump --yes, commit fix: other, run cz bump --yes.
  4. CHANGELOG.md has ## 1.1.1, ## 1.1.0 and ## 1.0.0, each once.

Additional Context

Open PRs touch some of the same files, so a rebase can be necessary:

🤖 Generated with Claude Code

By default, the release title in the changelog is the tag name.
With `tag_format = "v$version"`, the title is `## v1.0.0`.

The new `changelog_use_bare_version` setting writes the version
without the `tag_format` prefix and suffix (`## 1.0.0`), for
`cz changelog` and `cz bump --changelog`. The default is `false`,
so existing changelogs do not change.

The incremental changelog finds the latest release from its title.
A bare title does not match `tag_format`, so the changelog formats
now also read bare versions when the setting is enabled. The git tag
of the release is then found by its version, so a release tagged in
a `legacy_tag_formats` format is found too (also when prereleases
are merged). Titles with the tag name are still read, so a project
with an existing changelog can enable the setting. If a title
contains both a bare version and a tag name (e.g. a compare link),
the first one is read (the last one in AsciiDoc). A version that is not
valid for the version scheme is ignored.

Closes commitizen-tools#562

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

codecov Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2141      +/-   ##
==========================================
+ Coverage   98.29%   98.31%   +0.02%     
==========================================
  Files          61       61              
  Lines        2874     2916      +42     
==========================================
+ Hits         2825     2867      +42     
  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.

In changelog version format should be without tag_format

1 participant