commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

feat: Introduce tag_regex option with smart default

Open robertschweizer opened this issue 2 years ago • 9 comments

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/format and ./scripts/test locally 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

robertschweizer avatar Mar 23 '23 15:03 robertschweizer

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%> (ø)

... and 9 files with indirect coverage changes

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Mar 23 '23 15:03 codecov[bot]

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.

robertschweizer avatar May 03 '23 06:05 robertschweizer

Hi @robertschweizer sorry for the late reply. I briefly walk through it. I like the idea and will definitely take a look after reworked 🙂

Lee-W avatar Jun 23 '23 11:06 Lee-W

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 a tag_regex.
  • cz bump --changelog sets the --incremental flag. This finds the previous version with a different logic than cz bump. The first line matching version_schema's parser in the existing changelog is used as previous version. This version is then formatted with tag_format and searched for in existing tags with a similarity threshold of 0.89.
  • Suspected bugs in cz changelog:
    • Existing tags (get_tags() function) and --rev-range values are validated by constructing the configured version_scheme on them. This means it matches packaging.Version._regex instead of BaseVersion.parser. Both SemVer and Pep440 version providers thus use packaging's PEP440 version matcher here.
      • The two standards require different pattern matching
    • --incremental uses version_schema but ignores tag_format to search changelog.
      • Probably cz bump --changelog should 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.
  • ScmProvider should really use some smarter default regex matching when a non-standard tag_format is set. Maybe using placeholders other than $version in tag_format should be deprecated to make this easier. The $version string can now be configured using version_scheme.

@Lee-W @noirbizarre

robertschweizer avatar Jun 27 '23 10:06 robertschweizer

Looks good, hopefully we can merge it soon

woile avatar Sep 14 '23 17:09 woile

Looks as great feature for monorepo. Any update on it?

AlexeySanko avatar May 24 '24 16:05 AlexeySanko