feat: Introduce tag_regex option with smart default
Description
Closes https://github.com/commitizen-tools/commitizen/issues/519
CLI flag name: --tag-regex
Heavily inspired by https://github.com/commitizen-tools/commitizen/pull/537, but extends it with a smart default value to exclude non-release tags. This was suggested in https://github.com/commitizen-tools/commitizen/issues/519#issuecomment-1163923719
I separated commits to make review easier.
Checklist
- [x] Add test cases to all the changes you introduce
- [x] Run
./scripts/formatand./scripts/testlocally to ensure this change passes linter check and test - [x] Test the changes on the local machine manually
- [x] Update the documentation for the changes
Expected behavior
Steps to Test This Pull Request
Additional context
Codecov Report
Patch coverage: 97.72% and project coverage change: +0.69 :tada:
Comparison is base (
f04a719) 97.35% compared to head (8eea9ea) 98.04%.
:exclamation: Current head 8eea9ea differs from pull request most recent head e58e56f. Consider uploading reports for the commit e58e56f to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #692 +/- ##
==========================================
+ Coverage 97.35% 98.04% +0.69%
==========================================
Files 42 41 -1
Lines 2041 1742 -299
==========================================
- Hits 1987 1708 -279
+ Misses 54 34 -20
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 98.04% <97.72%> (+0.69%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| commitizen/bump.py | 100.00% <ø> (ø) |
|
| commitizen/cli.py | 93.93% <ø> (-0.27%) |
:arrow_down: |
| commitizen/commands/init.py | 88.03% <66.66%> (+0.59%) |
:arrow_up: |
| commitizen/changelog.py | 99.43% <100.00%> (-0.07%) |
:arrow_down: |
| commitizen/commands/bump.py | 97.48% <100.00%> (-0.67%) |
:arrow_down: |
| commitizen/commands/changelog.py | 98.94% <100.00%> (ø) |
|
| commitizen/defaults.py | 100.00% <100.00%> (ø) |
|
| commitizen/git.py | 98.61% <100.00%> (+0.01%) |
:arrow_up: |
| commitizen/tags.py | 100.00% <100.00%> (ø) |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
It looks like these changes need some reworking because they partially duplicate what was done in https://github.com/commitizen-tools/commitizen/commit/3a1af6a1b3299841d450a4f07b89fb918abc5cad.
Would you merge this if I rework it? It didn't get a review before.
Hi @robertschweizer sorry for the late reply. I briefly walk through it. I like the idea and will definitely take a look after reworked 🙂
Sorry, I don't have much time at the moment. I started rebasing the first commit and opened https://github.com/commitizen-tools/commitizen/pull/775 to get that merged.
To continue here (not sure if I will find the time myself), it's important to consider:
- My use-case is to ignore tags in the changelog that we don't care about when running
cz bump --changelog. I probably don't need atag_regex. cz bump --changelogsets the--incrementalflag. This finds the previous version with a different logic thancz bump. The first line matchingversion_schema'sparserin the existing changelog is used as previous version. This version is then formatted withtag_formatand searched for in existing tags with a similarity threshold of 0.89.- Suspected bugs in
cz changelog:- Existing tags (
get_tags()function) and--rev-rangevalues are validated by constructing the configuredversion_schemeon them. This means it matchespackaging.Version._regexinstead ofBaseVersion.parser. BothSemVerandPep440version providers thus usepackaging's PEP440 version matcher here.- The two standards require different pattern matching
--incrementalusesversion_schemabut ignorestag_formatto search changelog.- Probably
cz bump --changelogshould pass the current (previous) release version explicitly, to make searching of the existing changelog unnecessary.- This would probably fix my use-case already.
- It's probably rather restrictive to require the changelog to contain the used Git tag names.
- Probably
- Existing tags (
ScmProvidershould really use some smarter default regex matching when a non-standardtag_formatis set. Maybe using placeholders other than$versionintag_formatshould be deprecated to make this easier. The$versionstring can now be configured usingversion_scheme.
@Lee-W @noirbizarre
Looks good, hopefully we can merge it soon
Looks as great feature for monorepo. Any update on it?