Movatterモバイル変換


[0]ホーム

URL:


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

Commitf0fdb6d

Browse files
committed
feat(changelog): add support for multiline BREAKING paragraph
Closes#346
1 parent2387ea7 commitf0fdb6d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

‎commitizen/changelog.py‎

Lines changed: 11 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
ifnotmatches:
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
ifmessage:
116118
parsed_message:Dict=message.groupdict()
117119
# change_type becomes optional by providing None
@@ -122,8 +124,15 @@ def generate_tree_from_commits(
122124
ifchangelog_message_builder_hook:
123125
parsed_message=changelog_message_builder_hook(parsed_message,commit)
124126
changes[change_type].append(parsed_message)
125-
ifmessage_body:
127+
128+
# Process body from commit message
129+
body_parts=commit.body.split("\n\n")
130+
forbody_partinbody_parts:
131+
message_body=body_map_pat.match(body_part)
132+
ifnotmessage_body:
133+
continue
126134
parsed_message_body:Dict=message_body.groupdict()
135+
127136
change_type=parsed_message_body.pop("change_type",None)
128137
changes[change_type].append(parsed_message_body)
129138

‎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+
deftest_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+
withpytest.raises(DryRunExit):
402+
cli.main()
403+
out,_=capsys.readouterr()
404+
405+
assertout== (
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
deftest_changelog_config_flag_increment(mocker,changelog_path,config_path):
391415

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp