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 9b911e3

Browse files
woileLee-W
authored andcommitted
feat(conventional_commits): use and proper support for conventional commits v1.0.0
1 parent 20449e9 commit 9b911e3

File tree

4 files changed

+70
-12
lines changed

4 files changed

+70
-12
lines changed

‎commitizen/changelog.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def generate_tree_from_commits(
7373
changelog_message_builder_hook: Optional[Callable] = None,
7474
) -> Iterable[Dict]:
7575
pat = re.compile(changelog_pattern)
76-
map_pat = re.compile(commit_parser)
76+
map_pat = re.compile(commit_parser, re.MULTILINE)
7777
# Check if the latest commit is not tagged
7878
latest_commit = commits[0]
7979
current_tag: Optional[GitTag] = get_commit_tag(latest_commit, tags)
@@ -109,7 +109,7 @@ def generate_tree_from_commits(
109109
continue
110110

111111
message = map_pat.match(commit.message)
112-
message_body = map_pat.match(commit.body)
112+
message_body = map_pat.search(commit.body)
113113
if message:
114114
parsed_message: Dict = message.groupdict()
115115
# change_type becomes optional by providing None

‎commitizen/cz/conventional_commits/conventional_commits.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ def questions(self) -> List[Dict[str, Any]]:
114114
"Imperative, lower case and no final dot:\n"
115115
),
116116
},
117-
{
118-
"type": "confirm",
119-
"message": "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer",
120-
"name": "is_breaking_change",
121-
"default": False,
122-
},
123117
{
124118
"type": "input",
125119
"name": "body",
@@ -129,6 +123,12 @@ def questions(self) -> List[Dict[str, Any]]:
129123
),
130124
"filter": multiple_line_breaker,
131125
},
126+
{
127+
"type": "confirm",
128+
"message": "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer",
129+
"name": "is_breaking_change",
130+
"default": False,
131+
},
132132
{
133133
"type": "input",
134134
"name": "footer",
@@ -150,10 +150,10 @@ def message(self, answers: dict) -> str:
150150

151151
if scope:
152152
scope = f"({scope})"
153-
if is_breaking_change:
154-
body = f"BREAKING CHANGE: {body}"
155153
if body:
156154
body = f"\n\n{body}"
155+
if is_breaking_change:
156+
footer = f"BREAKING CHANGE: {footer}"
157157
if footer:
158158
footer = f"\n\n{footer}"
159159

‎tests/commands/test_changelog_command.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,43 @@ def test_changelog_in_non_git_project(tmpdir, config, mocker):
349349
with tmpdir.as_cwd():
350350
with pytest.raises(NotAGitProjectError):
351351
cli.main()
352+
353+
354+
@pytest.mark.usefixtures("tmp_commitizen_project")
355+
def test_breaking_change_content_v1_beta(mocker, capsys):
356+
commit_message = (
357+
"feat(users): email pattern corrected\n\n"
358+
"BREAKING CHANGE: migrate by renaming user to users\n\n"
359+
"footer content"
360+
)
361+
create_file_and_commit(commit_message)
362+
testargs = ["cz", "changelog", "--dry-run"]
363+
mocker.patch.object(sys, "argv", testargs)
364+
with pytest.raises(DryRunExit):
365+
cli.main()
366+
out, _ = capsys.readouterr()
367+
368+
assert out == (
369+
"## Unreleased\n\n### Feat\n\n- **users**: email pattern corrected\n\n"
370+
"### BREAKING CHANGE\n\n- migrate by renaming user to users\n\n"
371+
)
372+
373+
374+
@pytest.mark.usefixtures("tmp_commitizen_project")
375+
def test_breaking_change_content_v1(mocker, capsys):
376+
commit_message = (
377+
"feat(users): email pattern corrected\n\n"
378+
"body content\n\n"
379+
"BREAKING CHANGE: migrate by renaming user to users"
380+
)
381+
create_file_and_commit(commit_message)
382+
testargs = ["cz", "changelog", "--dry-run"]
383+
mocker.patch.object(sys, "argv", testargs)
384+
with pytest.raises(DryRunExit):
385+
cli.main()
386+
out, _ = capsys.readouterr()
387+
388+
assert out == (
389+
"## Unreleased\n\n### Feat\n\n- **users**: email pattern corrected\n\n"
390+
"### BREAKING CHANGE\n\n- migrate by renaming user to users\n\n"
391+
)

‎tests/test_cz_conventional_commits.py‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,32 @@ def test_long_answer(config):
8282
"prefix": "fix",
8383
"scope": "users",
8484
"subject": "email pattern corrected",
85-
"is_breaking_change": True,
85+
"is_breaking_change": False,
8686
"body": "complete content",
8787
"footer": "closes #24",
8888
}
8989
message = conventional_commits.message(answers)
9090
assert (
9191
message
92-
== "fix(users): email pattern corrected\n\nBREAKING CHANGE: complete content\n\ncloses #24" # noqa
92+
== "fix(users): email pattern corrected\n\ncomplete content\n\ncloses #24" # noqa
93+
)
94+
95+
96+
def test_breaking_change_in_footer(config):
97+
conventional_commits = ConventionalCommitsCz(config)
98+
answers = {
99+
"prefix": "fix",
100+
"scope": "users",
101+
"subject": "email pattern corrected",
102+
"is_breaking_change": True,
103+
"body": "complete content",
104+
"footer": "migrate by renaming user to users",
105+
}
106+
message = conventional_commits.message(answers)
107+
print(message)
108+
assert (
109+
message
110+
== "fix(users): email pattern corrected\n\ncomplete content\n\nBREAKING CHANGE: migrate by renaming user to users" # noqa
93111
)
94112

95113

0 commit comments

Comments
(0)

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