fix(bump): preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog#1850
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1850 +/- ##
==========================================
- Coverage 97.99% 97.91% -0.08%
==========================================
Files 60 60
Lines 2691 2692 +1
==========================================
- Hits 2637 2636 -1
- Misses 54 56 +2 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
…rerelease` is used with `cz bump --changelog` Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
…rerelease` is used with `cz bump --changelog`, and no prereleases exist Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
0c3bced to
778edcb
Compare
<!-- Please, go through these steps when you submit a PR. 1. Make sure your branch is not protected. In particular, avoid making PRs from the `main` branch of your fork. 2. Give a descriptive title to your PR. We use semantic titles, and the accepted types and scopes are listed in https://github.com/meltano/meltano/blob/main/.github/semantic.yml. A good title should look like this: ``` feat(cli): The `meltano run` command now accepts a `--timeout` option to limit the time it runs ``` 3. Provide a description of your changes. 4. Put "Closes #XXXX" in your comment to auto-close the issue that your PR fixes (if such). --> ## Description <!-- Describe the changes introduced by this PR --> ## Related Issues * commitizen-tools/commitizen#1850 Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
<!-- Please, go through these steps when you submit a PR. 1. Make sure your branch is not protected. In particular, avoid making PRs from the `main` branch of your fork. 2. Give a descriptive title to your PR. We use semantic titles, and the accepted types and scopes are listed in https://github.com/meltano/meltano/blob/main/.github/semantic.yml. A good title should look like this: ``` feat(cli): The `meltano run` command now accepts a `--timeout` option to limit the time it runs ``` 3. Provide a description of your changes. 4. Put "Closes #XXXX" in your comment to auto-close the issue that your PR fixes (if such). --> ## Description <!-- Describe the changes introduced by this PR --> ## Related Issues * commitizen-tools/commitizen#1850 Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
bearomorphism
left a comment
There was a problem hiding this comment.
Thanks you for reporting this issue and providing a fix! A few nits
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
227e12e to
397abe7
Compare
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
|
Thanks for the review @bearomorphism, this is ready for another pass. |
|
Thanks! |
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
changelog_merge_prerelease is used with cz bump --changelogchangelog_merge_prerelease is used with cz bump --changelog
|
Thanks for the feedback again @bearomorphism! In the latest commit I put all the relevant cases to my usecase in a single parametrized test:
In all cases I'm interested in the changelog header is preserved 😀 |
There was a problem hiding this comment.
Pull request overview
Fixes a regression in Commitizen’s bump + changelog generation where enabling changelog_merge_prerelease could remove the existing changelog header during cz bump --changelog.
Changes:
- Update changelog generation logic to preserve existing header content when prerelease-merging is enabled.
- Add regression test coverage for preserving the changelog header across prerelease/no-prerelease and merge/no-merge scenarios.
- Add file-regression snapshots for the new header-preservation test cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
commitizen/commands/changelog.py |
Adjusts prerelease-merge metadata handling so incremental writes don’t drop the preamble/header. |
tests/commands/test_bump_command.py |
Adds a new parametrized regression test ensuring headers are preserved under different prerelease/merge combinations. |
tests/commands/test_bump_command/test_changelog_merge_preserves_header_without_prerelease_.md |
Snapshot for header-preservation case with no prerelease involved. |
tests/commands/test_bump_command/test_changelog_merge_preserves_header_with_prerelease_no_merge_.md |
Snapshot for prerelease present but merging disabled. |
tests/commands/test_bump_command/test_changelog_merge_preserves_header_with_prerelease_merge_.md |
Snapshot for prerelease present and merging enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_deprecate_files_only(util: UtilFixture): | ||
| util.create_file_and_commit("feat: new file") | ||
| with ( | ||
| pytest.warns(DeprecationWarning, match=r".*--files-only.*deprecated"), | ||
| pytest.raises(ExpectedExit), | ||
| ): | ||
| util.run_cli("bump", "--yes", "--files-only") | ||
| @pytest.mark.freeze_time("2025-01-01") | ||
| def test_changelog_merge_preserves_header( | ||
| mocker: MockFixture, | ||
| util: UtilFixture, | ||
| changelog_path: Path, |
There was a problem hiding this comment.
The existing deprecation test for --files-only (test_bump_deprecate_files_only) was removed in this hunk and doesn’t appear elsewhere in the test suite. This drops coverage for the expected DeprecationWarning + ExpectedExit behavior; please restore the test (or add an equivalent) alongside the new changelog header regression tests.
There was a problem hiding this comment.
My fault I didn't see this section...
There was a problem hiding this comment.
Ah, sorry about that!
I saw the drop in coverage for --files-only but didn't think more of that 🤦
Description
Fixes a regression introduced in v4.11.3 (370ac9d, #1700) where using
cz bump --changelogwithchangelog_merge_prerelease = trueresults in the header of the existing changelog file being removed.Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsDocumentation Changes
uv run poe doclocally to ensure the documentation pages renders correctlyExpected Behavior
Steps to Test This Pull Request
Additional Context