Skip to content

Conversation

@zimmermannJakob
Copy link

@zimmermannJakobzimmermannJakob commented Dec 7, 2025

Description

This PR solves issue #1694.

Checklist

Code Changes

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and tests (Some error out on mac. I will investigate if they fail in ci)
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions (I thought about breaking changes and starting an empty changelog with prereleases.)
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
      - [ ] Update the documentation for the changes (I do not think this applies. It works now as documented.)

### Documentation Changes

- [ ] Run poetry doc locally to ensure the documentation pages renders correctly
- [ ] Check and fix any broken links (internal or external) in the documentation

When running poetry doc, any broken internal documentation links will be reported in the console output like this:

INFO - Doc file 'config.md' contains a link 'commands/bump.md#-post_bump_hooks', but the doc 'commands/bump.md' does not contain an anchor '#-post_bump_hooks'. 

Expected Behavior

See issue #1694.

Steps to Test This Pull Request

  1. build the changes on the branch. poetry build.
  2. Take the resulting .wheel file from dist/
  3. Install the file in a separate python environment:
  • python3 -m venv .venv && source .venv/bin/activate
  • verify env: which pip
  • pip install commitizen-4.10.0-py3-none-any.whl
  1. Go through the steps in the issue description and try reproducing the bug.

Additional Context

Known issue: When the changelog only contains pre-releases, the old behavior can still be observed. (Fixed)

@codecov
Copy link

codecovbot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.91%. Comparing base (120d514) to head (646cc6c).
⚠️ Report is 886 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #1700 +/- ## ========================================== + Coverage 97.33% 97.91% +0.57%  ========================================== Files 42 60 +18 Lines 2104 2641 +537 ========================================== + Hits 2048 2586 +538 + Misses 56 55 -1 
FlagCoverage Δ
unittests97.91% <100.00%> (+0.57%)⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zimmermannJakobzimmermannJakob marked this pull request as ready for review December 13, 2025 14:29
Copy link
Member

@woilewoile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!

cli.main()

testargs= ["cz", "bump", "--changelog"]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this blank line

Comment on lines +108 to +111
ifduring_version_bumpandrules.merge_prereleases:
current_tag=None
else:
current_tag=get_commit_tag(commits[0], tags) ifcommitselseNone
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ifduring_version_bumpandrules.merge_prereleases:
current_tag=None
else:
current_tag=get_commit_tag(commits[0], tags) ifcommitselseNone
ifduring_version_bumpandrules.merge_prereleasesandnotcommits:
current_tag=None
else:
# Check if the latest commit is not tagged
current_tag=get_commit_tag(commits[0], tags)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be or not commits, in which case I find it more readable as is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks

"incremental": True,
"dry_run": dry_run,
"during_version_bump": self.arguments["prerelease"]
isNone, # We let the changelog implementation know that we want to replace prereleases while staying incremental AND the new tag does not exist already
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is a bit unclear to me.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. Was more of a note to self. I changed it to something more meaningful.

latest_version_index=index
line=line.strip().lower()

parsed=self.parse_version_from_title(line)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the variable parsed to something more clear? Such as parsed_version. As well as the parsed in another function get_metadata_from_file.

Thanks!

Comment on lines 92 to 95
ifparsed:
ifnotself.tag_rules.extract_version(
GitTag(parsed.tag, "", "")
).is_prerelease:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine these if statements with and

) aschangelog_file:
returnself.get_latest_full_release_from_file(changelog_file)

defget_latest_full_release_from_file(self, file: IO[Any]) ->IncrementalMergeInfo:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why extract this function? I don't see any benefits.

You could put the whole function body under with open block and the logic is still clear.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the same pattern as with metadata, which also has an interface calling the get function, which in turn calls the get_from_file function. I think both works, but I would prefer to leave it as is to stay consistent.

@zimmermannJakob
Copy link
Author

@woile@bearomorphism Thank you for your reviews!
@bearomorphism I applied your suggestions, but left the conversations open for you to verify. Where I disagreed with a suggestion, I stated why.

@bearomorphism
Copy link
Collaborator

The latest commit should not be chore. I'd suggest you to rebase the commits and adjust the commit messages, so the commit history will be cleaner after merging

@bearomorphism
Copy link
Collaborator

I believe there is a way to mock the datetime in your new tests

@bearomorphism
Copy link
Collaborator

bearomorphism commented Dec 16, 2025

I remember git commit timestamp can be specified

Thanks!🙏

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@zimmermannJakob@bearomorphism@woile