Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def generate_tree_from_commits(
changelog_message_builder_hook: Optional[Callable] = None,
) -> Iterable[Dict]:
pat = re.compile(changelog_pattern)
map_pat = re.compile(commit_parser)
map_pat = re.compile(commit_parser, re.MULTILINE)
# Check if the latest commit is not tagged
latest_commit = commits[0]
current_tag: Optional[GitTag] = get_commit_tag(latest_commit, tags)
Expand Down Expand Up @@ -109,7 +109,7 @@ def generate_tree_from_commits(
continue

message = map_pat.match(commit.message)
message_body = map_pat.match(commit.body)
message_body = map_pat.search(commit.body)
if message:
parsed_message: Dict = message.groupdict()
# change_type becomes optional by providing None
Expand Down
16 changes: 8 additions & 8 deletions commitizen/cz/conventional_commits/conventional_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ def questions(self) -> List[Dict[str, Any]]:
"Imperative, lower case and no final dot:\n"
),
},
{
"type": "confirm",
"message": "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer",
"name": "is_breaking_change",
"default": False,
},
{
"type": "input",
"name": "body",
Expand All @@ -129,6 +123,12 @@ def questions(self) -> List[Dict[str, Any]]:
),
"filter": multiple_line_breaker,
},
{
"type": "confirm",
"message": "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer",
"name": "is_breaking_change",
"default": False,
},
{
"type": "input",
"name": "footer",
Expand All @@ -150,10 +150,10 @@ def message(self, answers: dict) -> str:

if scope:
scope = f"({scope})"
if is_breaking_change:
body = f"BREAKING CHANGE: {body}"
if body:
body = f"\n\n{body}"
if is_breaking_change:
footer = f"BREAKING CHANGE: {footer}"
if footer:
footer = f"\n\n{footer}"

Expand Down
40 changes: 40 additions & 0 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,43 @@ def test_changelog_in_non_git_project(tmpdir, config, mocker):
with tmpdir.as_cwd():
with pytest.raises(NotAGitProjectError):
cli.main()


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_breaking_change_content_v1_beta(mocker, capsys):
commit_message = (
"feat(users): email pattern corrected\n\n"
"BREAKING CHANGE: migrate by renaming user to users\n\n"
"footer content"
)
create_file_and_commit(commit_message)
testargs = ["cz", "changelog", "--dry-run"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(DryRunExit):
cli.main()
out, _ = capsys.readouterr()

assert out == (
"## Unreleased\n\n### Feat\n\n- **users**: email pattern corrected\n\n"
"### BREAKING CHANGE\n\n- migrate by renaming user to users\n\n"
)


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_breaking_change_content_v1(mocker, capsys):
commit_message = (
"feat(users): email pattern corrected\n\n"
"body content\n\n"
"BREAKING CHANGE: migrate by renaming user to users"
)
create_file_and_commit(commit_message)
testargs = ["cz", "changelog", "--dry-run"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(DryRunExit):
cli.main()
out, _ = capsys.readouterr()

assert out == (
"## Unreleased\n\n### Feat\n\n- **users**: email pattern corrected\n\n"
"### BREAKING CHANGE\n\n- migrate by renaming user to users\n\n"
)
22 changes: 20 additions & 2 deletions tests/test_cz_conventional_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,32 @@ def test_long_answer(config):
"prefix": "fix",
"scope": "users",
"subject": "email pattern corrected",
"is_breaking_change": True,
"is_breaking_change": False,
"body": "complete content",
"footer": "closes #24",
}
message = conventional_commits.message(answers)
assert (
message
== "fix(users): email pattern corrected\n\nBREAKING CHANGE: complete content\n\ncloses #24" # noqa
== "fix(users): email pattern corrected\n\ncomplete content\n\ncloses #24" # noqa
)


def test_breaking_change_in_footer(config):
conventional_commits = ConventionalCommitsCz(config)
answers = {
"prefix": "fix",
"scope": "users",
"subject": "email pattern corrected",
"is_breaking_change": True,
"body": "complete content",
"footer": "migrate by renaming user to users",
}
message = conventional_commits.message(answers)
print(message)
assert (
message
== "fix(users): email pattern corrected\n\ncomplete content\n\nBREAKING CHANGE: migrate by renaming user to users" # noqa
)


Expand Down