Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6656cb4

Browse files
authored
Merge pull request #728 from commitizen-tools/fix/673-breaking-change
test: add test for 'additional' types in conventional commits
2 parents 93fd3af + 376427c commit 6656cb4

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

‎commitizen/bump.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
def find_increment(
2424
commits: List[GitCommit], regex: str, increments_map: Union[dict, OrderedDict]
2525
) -> Optional[str]:
26-
2726
if isinstance(increments_map, dict):
2827
increments_map = OrderedDict(increments_map)
2928

@@ -35,16 +34,17 @@ def find_increment(
3534
for commit in commits:
3635
for message in commit.message.split("\n"):
3736
result = select_pattern.search(message)
37+
3838
if result:
39-
found_keyword = result.group(0)
39+
found_keyword = result.group(1)
4040
new_increment = None
4141
for match_pattern in increments_map.keys():
4242
if re.match(match_pattern, found_keyword):
4343
new_increment = increments_map[match_pattern]
4444
break
4545

4646
if increment == "MAJOR":
47-
continue
47+
break
4848
elif increment == "MINOR" and new_increment == "MAJOR":
4949
increment = new_increment
5050
elif increment == "PATCH" or increment is None:
@@ -103,7 +103,6 @@ def semver_generator(current_version: str, increment: str = None) -> str:
103103
# so it doesn't matter the increment.
104104
# Example: 1.0.0a0 with PATCH/MINOR -> 1.0.0
105105
if not version.is_prerelease:
106-
107106
if increment == MAJOR:
108107
increments_version[MAJOR] += 1
109108
increments_version[MINOR] = 0

‎commitizen/defaults.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Settings(TypedDict, total=False):
8888
MINOR = "MINOR"
8989
PATCH = "PATCH"
9090

91-
bump_pattern = r"^(BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?"
91+
bump_pattern = r"^(((BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?)|\w+!):"
9292
bump_map = OrderedDict(
9393
(
9494
(r"^.+!$", MAJOR),
@@ -112,5 +112,5 @@ class Settings(TypedDict, total=False):
112112
change_type_order = ["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]
113113
bump_message = "bump: version $current_version → $new_version"
114114

115-
commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?" # noqa
115+
commit_parser = r"^((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?|\w+!):\s(?P<message>.*)?" # noqa
116116
version_parser = r"(?P<version>([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?(\w+)?)"

‎tests/commands/test_changelog_command.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,36 @@ def test_breaking_change_content_v1_multiline(
516516
file_regression.check(out, extension=".md")
517517

518518

519+
@pytest.mark.usefixtures("tmp_commitizen_project")
520+
def test_breaking_change_content_v1_with_exclamation_mark(
521+
mocker: MockFixture, capsys, file_regression
522+
):
523+
commit_message = "chore!: drop support for py36"
524+
create_file_and_commit(commit_message)
525+
testargs = ["cz", "changelog", "--dry-run"]
526+
mocker.patch.object(sys, "argv", testargs)
527+
with pytest.raises(DryRunExit):
528+
cli.main()
529+
out, _ = capsys.readouterr()
530+
531+
file_regression.check(out, extension=".md")
532+
533+
534+
@pytest.mark.usefixtures("tmp_commitizen_project")
535+
def test_breaking_change_content_v1_with_exclamation_mark_feat(
536+
mocker: MockFixture, capsys, file_regression
537+
):
538+
commit_message = "feat(pipeline)!: some text with breaking change"
539+
create_file_and_commit(commit_message)
540+
testargs = ["cz", "changelog", "--dry-run"]
541+
mocker.patch.object(sys, "argv", testargs)
542+
with pytest.raises(DryRunExit):
543+
cli.main()
544+
out, _ = capsys.readouterr()
545+
546+
file_regression.check(out, extension=".md")
547+
548+
519549
@pytest.mark.usefixtures("tmp_commitizen_project")
520550
def test_changelog_config_flag_increment(
521551
mocker: MockFixture, changelog_path, config_path, file_regression
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Unreleased
2+
3+
4+
- drop support for py36
5+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Unreleased
2+
3+
### Feat
4+
5+
- **pipeline**: some text with breaking change
6+

‎tests/test_bump_find_increment.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from commitizen.cz.conventional_commits import ConventionalCommitsCz
99
from commitizen.git import GitCommit
1010

11-
NONE_INCREMENT_CC = ["docs(README): motivation", "ci: added travis"]
11+
NONE_INCREMENT_CC = [
12+
"docs(README): motivation",
13+
"ci: added travis",
14+
"performance. Remove or disable the reimplemented linters",
15+
"refactor that how this line starts",
16+
]
1217

1318
PATCH_INCREMENTS_CC = [
1419
"fix(setup.py): future is now required for every python version",
@@ -19,6 +24,8 @@
1924
"feat(cli): added version",
2025
"docs(README): motivation",
2126
"fix(setup.py): future is now required for every python version",
27+
"perf: app is much faster",
28+
"refactor: app is much faster",
2229
]
2330

2431
MAJOR_INCREMENTS_BREAKING_CHANGE_CC = [
@@ -41,6 +48,16 @@
4148
"fix(setup.py): future is now required for every python version",
4249
]
4350

51+
MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2 = [
52+
"feat(pipeline)!: some text with breaking change"
53+
]
54+
55+
MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC = [
56+
"chore!: drop support for Python 3.9",
57+
"docs(README): motivation",
58+
"fix(setup.py): future is now required for every python version",
59+
]
60+
4461
PATCH_INCREMENTS_SVE = ["readme motivation PATCH", "fix setup.py PATCH"]
4562

4663
MINOR_INCREMENTS_SVE = [
@@ -67,7 +84,9 @@
6784
(MINOR_INCREMENTS_CC, "MINOR"),
6885
(MAJOR_INCREMENTS_BREAKING_CHANGE_CC, "MAJOR"),
6986
(MAJOR_INCREMENTS_BREAKING_CHANGE_ALT_CC, "MAJOR"),
87+
(MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC, "MAJOR"),
7088
(MAJOR_INCREMENTS_EXCLAMATION_CC, "MAJOR"),
89+
(MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2, "MAJOR"),
7190
(NONE_INCREMENT_CC, None),
7291
),
7392
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /