Skip to content

fix: ignore invalid tags #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carlossg
Copy link
Contributor

Starting in 4.4.0 due to #1297 when an invalid tag is present an exception is thrown

This commit ignores the invalid tags

Follow up from #1375

Description

Starting in 4.4.0 due to #1297 when an invalid tag is present an exception is thrown

This commit ignores the invalid tags

Follow up from #1375

Checklist

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

in https://github.com/carlossg/commitizen-test.git the fix changes from

❯ cz bump --dry-run
Traceback (most recent call last):
  File "/opt/homebrew/bin/cz", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.7.0/libexec/lib/python3.13/site-packages/commitizen/cli.py", line 656, in main
    args.func(conf, arguments)()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.7.0/libexec/lib/python3.13/site-packages/commitizen/commands/bump.py", line 147, in __call__
    current_version = self.scheme(provider.get_version())
                                  ~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.7.0/libexec/lib/python3.13/site-packages/commitizen/providers/scm_provider.py", line 21, in get_version
    versions = sorted(rules.extract_version(t) for t in version_tags)
  File "/opt/homebrew/Cellar/commitizen/4.7.0/libexec/lib/python3.13/site-packages/commitizen/providers/scm_provider.py", line 21, in <genexpr>
    versions = sorted(rules.extract_version(t) for t in version_tags)
                      ~~~~~~~~~~~~~~~~~~~~~^^^
  File "/opt/homebrew/Cellar/commitizen/4.7.0/libexec/lib/python3.13/site-packages/commitizen/tags.py", line 149, in extract_version
    raise InvalidVersion(
        f"Invalid version tag: '{tag.name}' does not match any configured tag format"
    )
packaging.version.InvalidVersion: Invalid version tag: '1.0.0.fb3a1d1' does not match any configured tag format

to

❯ cz bump --dry-run
bump: version 1.0.0 → 1.1.0
tag to create: 1.1.0
increment detected: MINOR

Steps to Test This Pull Request

Additional context

Starting in 4.4.0 due to commitizen-tools#1297 when an invalid tag is present an exception is thrown

This commit ignores the invalid tags

Follow up from commitizen-tools#1375
Copy link

codecov bot commented May 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.58%. Comparing base (120d514) to head (ba5e539).
Report is 606 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1410      +/-   ##
==========================================
+ Coverage   97.33%   97.58%   +0.24%     
==========================================
  Files          42       57      +15     
  Lines        2104     2687     +583     
==========================================
+ Hits         2048     2622     +574     
- Misses         56       65       +9     
Flag Coverage Δ
unittests 97.58% <100.00%> (+0.24%) ⬆️

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.

Copy link
Member

@noirbizarre noirbizarre left a comment

Choose a reason for hiding this comment

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

I would says silencing exception with try..except..pass is never a good solution.
The exception was already raised before the PR (it was actually the reason for the PR as it was producing 1 error line by tag). The fact that it's breaking now is an unexpected side-effect which should be fixed, but silencing and ignoring them totally can't be the solution. It allows to see when you make a mistake on the tag or you forget some or when you tag are legitimately invalid (which seem to be your case)

I think there is 3 acceptable solutions:

  • fix the regression and make the exception non-breaking with 1 error line by exception
  • make an explicit opt-in option to ignore them
  • handle the fact that your tags are not valid by:
    • using the dedicated ignored_tag_formats option to ignore them if you don't want them in your changelog (which given you were intending to silence the exception seem to fit your use case)
    • using a version_scheme in which they are valid if you want them in your changelog

I think that fixing the regression is the path to follow (I need to re-read the PR comments to be sure we did not choose to make it breaking given the possibility to explicitly ignore them) but your case should already be already handled by using ignored_tag_formats = ["${major}-${minor}-${patch}-*"]

Sign up for free to 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.

2 participants