Repository navigation
feat(changelog): add changelog_use_bare_version setting - #2141
Open
pranjalbhatia710 wants to merge 1 commit into
Open
pranjalbhatia710 wants to merge 1 commit into
pranjalbhatia710 wants to merge 1 commit into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_versionsetting. When it istrue, release titles in the changelog contain the version without thetag_formatprefix and suffix: withtag_format = "v$version", the title is## 1.0.0instead of## v1.0.0. The default isfalse, so existing changelogs do not change.Root cause:
generate_tree_from_commitsincommitizen/changelog.pyusestag.nameas the release title, so thetag_formatprefix is always in the title.Fix:
TagRules.extract_version(tag)(falls back to the tag name). This is the version as normalized by the version scheme, so a tagv1.0.0-rc1underpep440is titled1.0.0rc1.cz bump --changelogpasses the new version as the unreleased version.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 alegacy_tag_formatsformat are found too, also withchangelog_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 callself.tag_rules.search_versionmust callself.search_versionto 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 defaulttag_format = "$version".docs/config/changelog.mdanddocs/config/configuration_file.md.The triage comment suggested
changelog_use_bare_versionorchangelog_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?
Generated-by: Claude Code following the guidelines
Assisted By: AI
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsuv run poe allwas not run as one command. Tested on macOS arm64, Python 3.13:ruff check,ruff format --checkandmypyoncommitizenandtests: clean.cz check --rev-range origin/master..HEAD: valid.pytest -n 4 tests: 1386 passed, 2 skipped, 2 xfailed.pytest --cov=commitizen --cov-report=term-missingover 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.pyat 100%).New tests (34 cases: 22 fail on
master, 8 of them because the tested functions are new; the other 12 pass onmasterbecause they check unchanged behaviour with the setting off or titles thatmasteralready reads correctly):cz changelogwith bare titles, repeated incrementalcz bump --changelog, enabling the setting on a changelog with tag-name titles, a bare title whose release is tagged in a legacy format.get_metadatawith a bare title in all four formats (Markdown, AsciiDoc, Textile, reStructuredText).changelog.get_release_title(setting off, setting on, legacy-format tag, tag that matches no format) andChangelog._find_release_tag(setting off, legacy-format tag, no matching tag, no version).Documentation Changes
uv run poe doclocally to ensure the documentation pages renders correctlyExpected Behavior
With
tag_format = "SOME_TAG_PREFIX_$version"andchangelog_use_bare_version = true,cz changelogandcz bump --changelogwrite## 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
pyproject.tomlwith:feat: initial, tagSOME_TAG_PREFIX_1.0.0, commitfeat(Testing): Testing something.cz bump --yes, commitfix: other, runcz bump --yes.CHANGELOG.mdhas## 1.1.1,## 1.1.0and## 1.0.0, each once.Additional Context
Open PRs touch some of the same files, so a rebase can be necessary:
commitizen/changelog_formats/base.py,commitizen/changelog_formats/restructuredtext.py(other lines ofget_metadata_from_file, near thesearch_versioncall changed here),tests/commands/test_changelog_command.py,tests/test_changelog_format_asciidoc.pyandtests/test_changelog_format_markdown.py.commitizen/commands/changelog.py(thetags = ...line just above thestart_revlines changed here) andtests/commands/test_changelog_command.py.tests/commands/test_bump_command.py.commitizen/changelog.py,tests/test_changelog.py.🤖 Generated with Claude Code