-
-
Notifications
You must be signed in to change notification settings - Fork 321
fix(bump): Preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog
#1850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edgarrmondragon
wants to merge
4
commits into
commitizen-tools:master
Choose a base branch
from
edgarrmondragon:fix/bump-changelog-merge-pre-removes-header
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−7
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0c430ae
test: Add a failing test
edgarrmondragon 681a433
fix(bump): Preserve existing changelog header when `changelog_merge_p…
edgarrmondragon 778edcb
fix(bump): Preserve existing changelog header when `changelog_merge_p…
edgarrmondragon fb214be
Merge branch 'master' into fix/bump-changelog-merge-pre-removes-header
edgarrmondragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1494,6 +1494,91 @@ def test_changelog_config_flag_merge_prerelease_only_prerelease_present( | |
| file_regression.check(out, extension=".md") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| @pytest.mark.freeze_time("2025-01-01") | ||
| def test_changelog_merge_prerelease_preserves_header( | ||
| mocker: MockFixture, | ||
| util: UtilFixture, | ||
| changelog_path: Path, | ||
| config_path: Path, | ||
| file_regression: FileRegressionFixture, | ||
| ): | ||
| """Test that merge_prerelease preserves existing changelog header.""" | ||
| with config_path.open("a") as f: | ||
| f.write("changelog_merge_prerelease = true\n") | ||
| f.write("update_changelog_on_bump = true\n") | ||
| f.write("annotated_tag = true\n") | ||
|
|
||
| # Create initial version with changelog that has a header | ||
| util.create_file_and_commit("irrelevant commit") | ||
| mocker.patch("commitizen.git.GitTag.date", "1970-01-01") | ||
| git.tag("0.1.0") | ||
|
|
||
| # Create a changelog with a header manually | ||
| changelog_path.write_text( | ||
| "# Changelog\n\nAll notable changes to this project will be documented here.\n\n## 0.1.0 (1970-01-01)\n" | ||
| ) | ||
|
|
||
| util.create_file_and_commit("feat: add new output") | ||
| util.create_file_and_commit("fix: output glitch") | ||
| util.run_cli("bump", "--prerelease", "alpha", "--yes") | ||
|
|
||
| util.run_cli("bump", "--changelog") | ||
|
|
||
| with changelog_path.open() as f: | ||
| out = f.read() | ||
|
|
||
| # The header should be preserved | ||
| assert out.startswith("# Changelog\n") | ||
| assert "All notable changes to this project will be documented here." in out | ||
|
Comment on lines
+1532
to
+1533
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These assertions aren't needed |
||
| file_regression.check(out, extension=".md") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| @pytest.mark.freeze_time("2025-01-01") | ||
| def test_changelog_merge_prerelease_no_prereleases_to_merge( | ||
| mocker: MockFixture, | ||
| util: UtilFixture, | ||
| changelog_path: Path, | ||
| config_path: Path, | ||
| file_regression: FileRegressionFixture, | ||
| ): | ||
| """Test that merge_prerelease works correctly when there are no prereleases. | ||
|
|
||
| When changelog_merge_prerelease is enabled but there are no prereleases to merge, | ||
| the normal incremental changelog behavior should apply and the existing changelog | ||
| content should be preserved. | ||
| """ | ||
| with config_path.open("a") as f: | ||
| f.write("changelog_merge_prerelease = true\n") | ||
| f.write("update_changelog_on_bump = true\n") | ||
| f.write("annotated_tag = true\n") | ||
|
|
||
| # Create initial version with changelog that has a header | ||
| util.create_file_and_commit("feat: initial feature") | ||
| mocker.patch("commitizen.git.GitTag.date", "1970-01-01") | ||
| git.tag("0.1.0") | ||
|
|
||
| # Create a changelog with a header manually | ||
| changelog_path.write_text( | ||
| "# Changelog\n\nAll notable changes.\n\n## 0.1.0 (1970-01-01)\n\n### Feat\n\n- initial feature\n" | ||
| ) | ||
|
|
||
| # Add new commits and do a regular bump (no prerelease) | ||
| util.create_file_and_commit("feat: add new output") | ||
| util.create_file_and_commit("fix: output glitch") | ||
| util.run_cli("bump", "--changelog") | ||
|
|
||
| with changelog_path.open() as f: | ||
| out = f.read() | ||
|
|
||
| # The header and existing content should be preserved | ||
| assert out.startswith("# Changelog\n") | ||
| assert "All notable changes." in out | ||
| assert "## 0.1.0 (1970-01-01)" in out | ||
|
Comment on lines
+1576
to
+1578
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| file_regression.check(out, extension=".md") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_deprecate_files_only(util: UtilFixture): | ||
| util.create_file_and_commit("feat: new file") | ||
|
|
||
19 changes: 19 additions & 0 deletions
19
...ds/test_bump_command/test_changelog_merge_prerelease_no_prereleases_to_merge.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes. | ||
|
|
||
| ## 0.2.0 (2025-01-01) | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 (1970-01-01) | ||
|
|
||
| ### Feat | ||
|
|
||
| - initial feature |
15 changes: 15 additions & 0 deletions
15
.../commands/test_bump_command/test_changelog_merge_prerelease_preserves_header.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented here. | ||
|
|
||
| ## 0.2.0 (2025-01-01) | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 (1970-01-01) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While
has_prereleases_to_mergeis descriptive, the conditionlatest_full_release_info.index is not Noneis duplicated and removing it will make mypy unhappy. The above comment is enough to help reader understand the intention behind this long expression.