Skip to content
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

generate changelog only from tags matching specific patterns #519

Open
bhelgs opened this issue May 24, 2022 · 3 comments · May be fixed by #692
Open

generate changelog only from tags matching specific patterns #519

bhelgs opened this issue May 24, 2022 · 3 comments · May be fixed by #692
Labels

Comments

@bhelgs
Copy link
Contributor

bhelgs commented May 24, 2022

Description

It seems right now the changelog generator is capturing all tags, rather than just the tags matching the version pattern.
It was mentioned in this TODO in the code.

Without filtering tags:

  • A user might create a pre-release tag v2.27.0-alpha and then later come to find it in their changelog.
    • it seems they would have to delete the tag
      otherwise they see v2.26.0...v2.27.0-alpha...v2.27.0 rather than v2.26.0...v2.27.0
    • (see "Additional context" section for more info if necessary)
  • It prevents users from having some sort of tagging practices unrelated to "release versions"
    • (see "Additional context" section for more info if necessary)

Possible Solution

  1. Allow users to specify a custom tag format via configuration regex.
    [tool.commitizen]
    # tag_format = "v$major.$minor.$patch$prerelease" # already used by "bump" (nothing new proposed)
    tag_parser = "v[0-9]*\.[0-9]\.[0-9]*" # proposed: filter for "released" versions only.
                                                             # tag_parser mirrors tag_format used by bump.
  2. Mimic current functionality by default (base commitizen):
    • match every tag by setting a default .* regex.

I believe this is an alternate solution to what was discussed on #364 and may be more extensible, for example:

  • The user could just edit tag_parser if they want multiple changelogs with different parse criteria
  • Capture each field within the version for use in other parts of changelog module:
    • v(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9]+)(?P<pre>[0-9A-Za-z-]?
  • The user may have changed their versioning pattern at some point and the parser would allow for that:
    • (v[0-9.]*|release-[0-9.]*) (pattern matches v1.2.0 or release-1.2.0)

Additional context

A user may have created a pre-release tag not knowing it would eventually show up in their changelog:

## v2.27.0 (2022-05-16)
### Feat
- added another thing
## v2.27.0-alpha (2022-05-16)
### Feat
-  let it respect pre-commit reformats when bumping
## v2.26.0 (2022-05-14)
### Feat
- Add --allow-abort option

When they really wanted:

## v2.27.0 (2022-05-16)
### Feat
- added another thing
-  let it respect pre-commit reformats when bumping
## v2.26.0 (2022-05-14)
### Feat
- Add --allow-abort option

Additional context

Other examples of when a repository may have some custom tags:

  • A team has a concept of "deliveries" that they are tagging.
  • A team has a feature branch that they have some kind of custom version tags for:
    • feature_for_user_x_method_B_v1.0
    • feature_for_user_x_method_B_v1.1
@bhelgs bhelgs added the type: feature A new enhacement proposal label May 24, 2022
@bhelgs
Copy link
Contributor Author

bhelgs commented Jun 1, 2022

Here is basically what the changes would look like to remove the TODO:
bhelgs@1910b96#diff-9a66aca02ea7d31a58e52fc33fc6914dc724c8eb36ccb69f365f86ec3490497bL106

Would you like a PR?

@hongkongkiwi
Copy link

I would actually classify this as a bit of a bug, because I've already set my tag format in config: tag_format: v$version.

I would expect that cz changelog only looks at tags matching this format? instead of pulling in unrelated tags.

I like the provided solution, could dev's merge this?

@woile
Copy link
Member

woile commented Jun 23, 2022

@bhelgs a PR would be more than welcome. I'll be back with commitizen by July, sorry for the slow response answer.

robertschweizer added a commit to robertschweizer/commitizen that referenced this issue Mar 23, 2023
Closes commitizen-tools#519

CLI flag name: --tag-regex

Heavily inspired by
commitizen-tools#537, but extends
it with a smart default value to exclude non-release tags. This was
suggested in
commitizen-tools#519 (comment)
robertschweizer added a commit to robertschweizer/commitizen that referenced this issue Mar 23, 2023
Closes commitizen-tools#519

CLI flag name: --tag-regex

Heavily inspired by
commitizen-tools#537, but extends
it with a smart default value to exclude non-release tags. This was
suggested in
commitizen-tools#519 (comment)
@robertschweizer robertschweizer linked a pull request Mar 23, 2023 that will close this issue
4 tasks
robertschweizer added a commit to robertschweizer/commitizen that referenced this issue May 2, 2023
Closes commitizen-tools#519

CLI flag name: --tag-regex

Heavily inspired by
commitizen-tools#537, but extends
it with a smart default value to exclude non-release tags. This was
suggested in
commitizen-tools#519 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants