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 0621bc4

Browse files
committed
feat(changelog): add support for multiline BREAKING paragraph
Closes #346
1 parent 2387ea7 commit 0621bc4

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

‎commitizen/changelog.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def generate_tree_from_commits(
7676
) -> Iterable[Dict]:
7777
pat = re.compile(changelog_pattern)
7878
map_pat = re.compile(commit_parser, re.MULTILINE)
79+
body_map_pat = re.compile(commit_parser, re.MULTILINE | re.DOTALL)
80+
7981
# Check if the latest commit is not tagged
8082
latest_commit = commits[0]
8183
current_tag: Optional[GitTag] = get_commit_tag(latest_commit, tags)
@@ -110,8 +112,8 @@ def generate_tree_from_commits(
110112
if not matches:
111113
continue
112114

115+
# Process subject from commit message
113116
message = map_pat.match(commit.message)
114-
message_body = map_pat.search(commit.body)
115117
if message:
116118
parsed_message: Dict = message.groupdict()
117119
# change_type becomes optional by providing None
@@ -122,9 +124,18 @@ def generate_tree_from_commits(
122124
if changelog_message_builder_hook:
123125
parsed_message = changelog_message_builder_hook(parsed_message, commit)
124126
changes[change_type].append(parsed_message)
125-
if message_body:
127+
128+
# Process body from commit message
129+
body_parts = commit.body.split("\n\n")
130+
for body_part in body_parts:
131+
message_body = body_map_pat.match(body_part)
132+
if not message_body:
133+
continue
126134
parsed_message_body: Dict = message_body.groupdict()
135+
127136
change_type = parsed_message_body.pop("change_type", None)
137+
if change_type_map:
138+
change_type = change_type_map.get(change_type, change_type)
128139
changes[change_type].append(parsed_message_body)
129140

130141
yield {"version": current_tag_name, "date": current_tag_date, "changes": changes}

‎setup.cfg‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ exclude =
3535
build,
3636
dist
3737
max-line-length = 88
38-
max-complexity = 11
38+
max-complexity = 12

‎tests/commands/test_changelog_command.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,30 @@ def test_breaking_change_content_v1(mocker, capsys):
386386
)
387387

388388

389+
@pytest.mark.usefixtures("tmp_commitizen_project")
390+
def test_breaking_change_content_v1_multiline(mocker, capsys):
391+
commit_message = (
392+
"feat(users): email pattern corrected\n\n"
393+
"body content\n\n"
394+
"BREAKING CHANGE: migrate by renaming user to users.\n"
395+
"and then connect the thingy with the other thingy\n\n"
396+
"footer content"
397+
)
398+
create_file_and_commit(commit_message)
399+
testargs = ["cz", "changelog", "--dry-run"]
400+
mocker.patch.object(sys, "argv", testargs)
401+
with pytest.raises(DryRunExit):
402+
cli.main()
403+
out, _ = capsys.readouterr()
404+
405+
assert out == (
406+
"## Unreleased\n\n### Feat\n\n- **users**: email pattern corrected\n\n"
407+
"### BREAKING CHANGE\n\n- migrate by renaming user to users.\n"
408+
"and then connect the thingy with the other thingy"
409+
"\n\n"
410+
)
411+
412+
389413
@pytest.mark.usefixtures("tmp_commitizen_project")
390414
def test_changelog_config_flag_increment(mocker, changelog_path, config_path):
391415

0 commit comments

Comments
(0)

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