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

adds a changelog tag parser to filter tags (--tag-parser; tag_parser) #537

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bhelgs
Copy link
Contributor

@bhelgs bhelgs commented Jul 19, 2022

Description

Some repositories have tags that are not matching the bump version pattern (e.g. alpha/beta release) #519.
It makes sense to be able to filter those out. See this "Expected Behavior" section for an example.

The first commit:

  1. feat: adds the filtering.

Subsequent commits (probably best reviewing each commit individually):

  1. test: adds a test for when a "feat:" commit is tagged. Previously only "bump:" commits were tagged.
  2. refactor: the linter was complaining. Mostly a copy/paste to reduce function complexity.
  3. refactor: further refactoring to reduce the number of if (by avoiding an optional).

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test 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

originally:

## v1.1.0(2022-02-13)
### Feat
- add more

## v1.1.0-beta (2022-02-13)
### Feat
- add new

## v1.0.0 (2022-02-13)
### Feat
- initial

once filtered with cz changelog --dry-run --tag-parser 'v[0-9]*\.[0-9]*\.[0-9]*' will be:

## v1.1.0 (2022-02-13)
### Feat
- add more
- add new

## v1.0.0 (2022-02-13)
### Feat
- initial

Similar can be done with the toml option: tag_parser: "v[0-9]*\\.[0-9]*\\.[0-9]*". Note toml required an extra \.

Steps to Test This Pull Request

  1. scripts/test

In the case below there is a filterable tag as the first commit.

## v1.2.0-beta (2022-02-13)
### Feat
- another thing

## v1.1.0 (2022-02-13)
### Feat
- add more
- add new

## v1.0.0 (2022-02-13)
### Feat
- initial

Question:

  • Should the v1.2.0-beta tag:
    • stay as ## v1.2.0-beta?
    • be replaced with ## Unreleased?
    • Maybe ## Prerelease tag: v1.2.0-beta?
    • be customizable?
  • No test in place yet.

Additional context

#519

@bhelgs
Copy link
Contributor Author

bhelgs commented Jul 19, 2022

@hongkongkiwi sorry that it took some time to get back to making this PR.

@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #537 (fbabc2a) into master (7b69599) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #537      +/-   ##
==========================================
+ Coverage   97.92%   97.94%   +0.02%     
==========================================
  Files          39       39              
  Lines        1540     1557      +17     
==========================================
+ Hits         1508     1525      +17     
  Misses         32       32              
Flag Coverage Δ
unittests 97.94% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
commitizen/cli.py 93.93% <ø> (ø)
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/changelog.py 96.73% <100.00%> (-0.53%) ⬇️
commitizen/commands/bump.py 96.42% <100.00%> (+1.23%) ⬆️
commitizen/commands/changelog.py 96.77% <100.00%> (+0.18%) ⬆️
commitizen/commands/check.py 100.00% <100.00%> (ø)
commitizen/cz/__init__.py 100.00% <100.00%> (ø)
commitizen/defaults.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7916511...fbabc2a. Read the comment docs.

bhelgs added 4 commits July 19, 2022 19:50
…parser)

The git tag parser is used to filter out undesired git tags from changelog. regex default is .* (all).
This new tag was added to a "feat:" rather than "bump:" commit.
The linter was complaining. Likely best to refactor this further.
Treats 'Unreleased' as if it is a git tag.
@bhelgs bhelgs force-pushed the add_optional_tag_parser branch from fff4d3b to fbabc2a Compare July 19, 2022 23:50
],
)
def test_changelog_tag_parser_config(
mocker, config_path, changelog_path, cli_args, line, filtered
Copy link
Member

Choose a reason for hiding this comment

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

Should we rename line as filter_pattern or something similar to make it even more readable?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could renamed filtered as is_filtered. I'm also a bit confused when reading it.

@pytest.mark.parametrize(
"tag_parser",
[
(None), # backwards compatibility check
Copy link
Member

Choose a reason for hiding this comment

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

Is the (, ) added by auto formatter? If not so, should we remove them?

@Lee-W Lee-W self-assigned this Sep 19, 2022
robertschweizer added a commit to robertschweizer/commitizen that referenced this pull request 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 pull request 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 pull request 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants