-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
bhelgs
wants to merge
4
commits into
commitizen-tools:master
Choose a base branch
from
bhelgs:add_optional_tag_parser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b795f41
feat(changelog): adds a tag parser to filter tags (--tag-parser; tag_…
bhelgs e1a780e
test(changelog): test a user defined tag (independent of bump)
bhelgs c6df321
refactor(changelog): reduces complexity of generate_tree_from_commits
bhelgs fbabc2a
refactor(changelog): refactor generate_tree_from_commits
bhelgs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import re | ||
from typing import Dict, Iterable, List, Pattern | ||
|
||
import pytest | ||
|
||
from commitizen import changelog, defaults, git | ||
|
@@ -458,6 +461,7 @@ | |
("v1.0.0", "aa44a92d68014d0da98965c0c2cb8c07957d4362", "2019-03-01"), | ||
("1.0.0b2", "aab33d13110f26604fb786878856ec0b9e5fc32b", "2019-01-18"), | ||
("v1.0.0b1", "7c7e96b723c2aaa1aec3a52561f680adf0b60e97", "2019-01-17"), | ||
("user_def", "ed830019581c83ba633bfd734720e6758eca6061", "2019-01-10"), | ||
("v0.9.11", "c52eca6f74f844ab3ffbde61d98ef96071e132b7", "2018-12-17"), | ||
("v0.9.10", "b3f89892222340150e32631ae6b7aab65230036f", "2018-09-22"), | ||
("v0.9.9", "684e0259cc95c7c5e94854608cd3dcebbd53219e", "2018-09-22"), | ||
|
@@ -642,9 +646,10 @@ def test_get_commit_tag_is_None(gitcommits, tags): | |
}, | ||
}, | ||
{"version": "1.0.0b2", "date": "2019-01-18", "changes": {}}, | ||
{"version": "v1.0.0b1", "date": "2019-01-17", "changes": {}}, | ||
{ | ||
"version": "v1.0.0b1", | ||
"date": "2019-01-17", | ||
"version": "user_def", | ||
"date": "2019-01-10", | ||
"changes": { | ||
"feat": [ | ||
{ | ||
|
@@ -790,14 +795,57 @@ def test_get_commit_tag_is_None(gitcommits, tags): | |
) | ||
|
||
|
||
def test_generate_tree_from_commits(gitcommits, tags): | ||
def _filter_tree(tag_pattern: Pattern, tree: Iterable[Dict]) -> List[Dict[str, str]]: | ||
"""filters the tree. commits with invalid tags are kept within the current node""" | ||
|
||
current = None | ||
out = [] | ||
for node in tree: | ||
if not current or tag_pattern.fullmatch(node["version"]) or not out: | ||
current = node.copy() | ||
out.append(current) | ||
else: | ||
changes = current["changes"] | ||
for key, value in node["changes"].items(): | ||
if key in changes: | ||
changes[key].extend(value) | ||
else: | ||
changes[key] = value | ||
|
||
return out | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"tag_parser", | ||
[ | ||
(None), # backwards compatibility check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the |
||
(".*"), # default tag_parser | ||
(r"v[0-9]*\.[0-9]*\.[0-9]*"), # version filter | ||
], | ||
) | ||
def test_generate_tree_from_commits(gitcommits, tags, tag_parser): | ||
parser = defaults.commit_parser | ||
changelog_pattern = defaults.bump_pattern | ||
tree = changelog.generate_tree_from_commits( | ||
gitcommits, tags, parser, changelog_pattern | ||
) | ||
|
||
assert tuple(tree) == COMMITS_TREE | ||
# generate the tree and expected_tree | ||
if tag_parser is None: | ||
tree = changelog.generate_tree_from_commits( | ||
gitcommits, tags, parser, changelog_pattern | ||
) | ||
# commits tree is unfiltered | ||
expected_tree = COMMITS_TREE | ||
else: | ||
tag_pattern = re.compile(tag_parser) | ||
tree = changelog.generate_tree_from_commits( | ||
gitcommits, tags, parser, changelog_pattern, tag_pattern=tag_pattern | ||
) | ||
# filter the COMMITS_TREE to what we expect it to be | ||
expected_tree = _filter_tree(tag_pattern, COMMITS_TREE) | ||
|
||
# compare the contents of each tree | ||
tree = list(tree) | ||
for outcome, expected in zip(tree, expected_tree): | ||
assert outcome == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename
line
asfilter_pattern
or something similar to make it even more readable?There was a problem hiding this comment.
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
asis_filtered
. I'm also a bit confused when reading it.