From 467ded02fcf91103bc57eb35c44bae0949166272 Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sun, 21 Sep 2025 11:40:37 +0800 Subject: [PATCH] refactor(ConventionalCommitsCz): rewrite message method to make the pattern more clear --- .../cz/conventional_commits/conventional_commits.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 689342347..c827cebb7 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -155,15 +155,16 @@ def message(self, answers: ConventionalCommitsAnswers) -> str: # type: ignore[o is_breaking_change = answers["is_breaking_change"] if scope: - scope = f"({scope})" - if body: - body = f"\n\n{body}" + # example: "fix(users): email pattern corrected" + first_line = f"{prefix}({scope}): {subject}" + else: + # example: "fix: email pattern corrected" + first_line = f"{prefix}: {subject}" + if is_breaking_change: footer = f"BREAKING CHANGE: {footer}" - if footer: - footer = f"\n\n{footer}" - return f"{prefix}{scope}: {subject}{body}{footer}" + return "\n\n".join(s for s in (first_line, body, footer) if s) def example(self) -> str: return (