Skip to content

Conversation

@bearomorphism
Copy link
Collaborator

@bearomorphismbearomorphism commented May 17, 2025

Closes#129

Description

Please see bump_rule.py, bump.py, cz/base.py, version_scheme.py and commands/bump.py (~350 lines).
The rest 1000+ lines are just tests and renaming.

  • Rewrote the bump pattern matching mechanism to make the algorithm more strict and maintainable.
  • Maintained backward compatibility with CustomBumpRule.
  • Simplified code.
  • Added a new Enum class SemVerIncrement and replace MAJOR, MINOR, PATCH with the Enum.
  • Now Prerelease is Enum.
  • Simplify find_increment logic in SemVerIncrement.get_highest_by_messages.
    • find_increment was the combination of 2 features: "finding the highest semantic version increment" and "parsing the semantic version increment from each git commit message".

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

Documentation Changes

  • Run poetry doc locally to ensure the documentation pages renders correctly

Expected Behavior

Steps to Test This Pull Request

Additional Context

@codecov
Copy link

codecovbot commented May 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.97%. Comparing base (d968f26) to head (9c3421c).

Additional details and impacted files
@@ Coverage Diff @@## refactors #1431 +/- ## ============================================= + Coverage 97.92% 97.97% +0.04%  ============================================= Files 58 59 +1 Lines 2704 2770 +66 ============================================= + Hits 2648 2714 +66  Misses 56 56 
FlagCoverage Δ
unittests97.97% <100.00%> (+0.04%)⬆️

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.

@bearomorphismbearomorphism changed the title refactor(bump_rule): add bump_rule interface, DefaultBumpRule and its…refactor(bump_rule): strict check and reorganizeMay 17, 2025
@bearomorphismbearomorphism marked this pull request as ready for review May 17, 2025 20:26
@bearomorphismbearomorphism changed the title refactor(bump_rule): strict check and reorganizefix(bump_rule): strict check and reorganizeMay 17, 2025
Comment on lines 94 to 153
self._BREAKING_CHANGE,
"fix",
"feat",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

This makes the pattern matching more strict.

Comment on lines 31 to 36
# TODO: deprecate these
bump_pattern: str|None=None
bump_map: dict[str, str] |None=None
bump_map_major_version_zero: dict[str, str] |None=None
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Not sure how to address these fields if we decide to check in the bump_rule change.

Comment on lines -44 to -54
ifnew_incrementisNone:
logger.debug(
f"no increment needed for '{found_keyword}' in '{message}'"
)

ifVERSION_TYPES.index(increment) <VERSION_TYPES.index(new_increment):
logger.debug(
f"increment detected is '{new_increment}' due to '{found_keyword}' in '{message}'"
)
increment=new_increment
Copy link
CollaboratorAuthor

@bearomorphismbearomorphismMay 17, 2025

Choose a reason for hiding this comment

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

I don't think we need these logs. The algorithm can be very simple as the current implementation of get_highest_by_messages

@bearomorphismbearomorphism mentioned this pull request May 18, 2025
10 tasks
@bearomorphism
Copy link
CollaboratorAuthor

The tests finally passed...

'MINOR'
"""
returnSemVerIncrement.get_highest(
get_increment(line)
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I don't think we need these logs. The algorithm can be very simple as the current implementation of find_increment_by_callable

We can log the traces in get_increment though.

Comment on lines 187 to 246
try:
ifret:=SemVerIncrement.get_highest(
(incrementforname, incrementinbump_map.items() ifm.group(name)),
):
returnret
exceptIndexError:
# Fallback to old school bump rule
pass
Copy link
CollaboratorAuthor

@bearomorphismbearomorphismMay 19, 2025

Choose a reason for hiding this comment

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

This addresses the problem mentioned in #129

#129 (comment)

@bearomorphismbearomorphism changed the title fix(bump_rule): strict check and reorganizefix(bump_rule): add BumpRule, enum SemVerIncrement and PrereleaseMay 19, 2025
@bearomorphism
Copy link
CollaboratorAuthor

Hope the doc string make it easier to review

@bearomorphismbearomorphism changed the title fix(bump_rule): add BumpRule, enum SemVerIncrement and Prereleasefeat(bump_rule): add BumpRule, VersionIncrement, Prerelease EnumMay 29, 2025
@bearomorphismbearomorphism changed the base branch from master to refactorsMay 31, 2025 18:11
@github-actionsgithub-actionsbot added the type: feature A new enhacement proposal label May 31, 2025
@Lee-WLee-W added this to the 4.9.0 milestone Jun 8, 2025
@Lee-WLee-Wforce-pushed the refactors branch 2 times, most recently from baee83e to a9cd957CompareJune 8, 2025 13:31
@bearomorphismbearomorphismforce-pushed the bump-rule-interface branch 2 times, most recently from fc31bee to 4279a25CompareJune 8, 2025 15:42
@bearomorphismbearomorphismforce-pushed the bump-rule-interface branch 2 times, most recently from 6e3caa5 to 8c7e2d3CompareJune 8, 2025 15:48
@Lee-WLee-W deleted the branch commitizen-tools:refactorsJune 9, 2025 14:18
@Lee-WLee-W closed this Jun 9, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use named capture group in bump_pattern to enable stricter check

2 participants

@bearomorphism@Lee-W