|
1 | 1 | import os |
2 | 2 | import re |
| 3 | +from typing import TypedDict |
3 | 4 |
|
4 | 5 | from commitizen import defaults |
5 | 6 | from commitizen.cz.base import BaseCommitizen |
@@ -27,6 +28,15 @@ def parse_subject(text): |
27 | 28 | return required_validator(text, msg="Subject is required.") |
28 | 29 |
|
29 | 30 |
|
| 31 | +class ConventionalCommitsAnswers(TypedDict): |
| 32 | + prefix: str |
| 33 | + scope: str |
| 34 | + subject: str |
| 35 | + body: str |
| 36 | + footer: str |
| 37 | + is_breaking_change: bool |
| 38 | + |
| 39 | + |
30 | 40 | class ConventionalCommitsCz(BaseCommitizen): |
31 | 41 | bump_pattern = defaults.BUMP_PATTERN |
32 | 42 | bump_map = defaults.BUMP_MAP |
@@ -147,24 +157,22 @@ def questions(self) -> Questions: |
147 | 157 | }, |
148 | 158 | ] |
149 | 159 |
|
150 | | - def message(self, answers: dict) -> str: |
151 | | - prefix = answers["prefix"] |
152 | | - scope = answers["scope"] |
153 | | - subject = answers["subject"] |
154 | | - body = answers["body"] |
155 | | - footer = answers["footer"] |
156 | | - is_breaking_change = answers["is_breaking_change"] |
| 160 | + def message(self, answers: ConventionalCommitsAnswers) -> str: # type: ignore[override] |
| 161 | + parts: list[str] = [answers["prefix"]] |
157 | 162 |
|
158 | | - if scope: |
159 | | - scope = f"({scope})" |
160 | | - if body: |
161 | | - body = f"\n\n{body}" |
162 | | - if is_breaking_change: |
| 163 | + if scope := answers["scope"]: |
| 164 | + parts.append(f"({scope})") |
| 165 | + parts.append(f": {answers['subject']}") |
| 166 | + if body := answers["body"]: |
| 167 | + parts.append(f"\n\n{body}") |
| 168 | + |
| 169 | + footer = answers["footer"] |
| 170 | + if answers["is_breaking_change"]: |
163 | 171 | footer = f"BREAKING CHANGE: {footer}" |
164 | 172 | if footer: |
165 | | - footer = f"\n\n{footer}" |
| 173 | + parts.append(f"\n\n{footer}") |
166 | 174 |
|
167 | | - return f"{prefix}{scope}: {subject}{body}{footer}" |
| 175 | + return "".join(parts) |
168 | 176 |
|
169 | 177 | def example(self) -> str: |
170 | 178 | return ( |
|
0 commit comments