Skip to content

Commit ecda657

Browse files
committed
feat: add changeup_hide_breaking option
Adds option for hiding breaking changes from commit body in changelog. BREAKING CHANGE: Breaking changes will now be hidden from the commit body and will only appear in the breaking change section. The behavior can be controlled with the newly added option `changeup_hide_breaking`.
1 parent 9a836b7 commit ecda657

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The behavior of the plugin can be customized by providing the following options
3939
| `changeup_repo_base_url` | The base URL for the repository, for instance `"https://github.com/my/repo"`. | `""` |
4040
| `changeup_show_hash` | Whether to add a link to the commit for each entry in the changelog. If `changeup_repo_base_url` is provided, the hash are linked to the commit. | `true` |
4141
| `changeup_show_body` | Whether to include the commit body in the changelog. | `true` |
42+
| `changeup_hide_breaking` | Whether to include the breaking changes section also in the the commit body if `changeup_show_body` is true. This prevents duplicate entries. | `true` |
4243
| `changeup_body_indent` | The number of spaces to indent the commit body if `changeup_show_body` is set to `true`. | `2` |
4344
| `changeup_link_issues` | If `true`, tries to convert issue numbers in phrases like `closes #21` to links. Only works if `changeup_repo_base_url` is provided. | `true` |
4445
| `changeup_scope_prefix` | Prefix for the scope of the change. | `"**"` |

src/cz_changeup/cz_changeup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ChangeupCz(ConventionalCommitsCz):
4646
repo_base_url: str = conf.settings.get("changeup_repo_base_url", "").strip(" /")
4747
show_hash: bool = conf.settings.get("changeup_show_hash", True)
4848
show_body: bool = conf.settings.get("changeup_show_body", True)
49+
hide_breaking: bool = conf.settings.get("changeup_hide_breaking", True)
4950
body_indent: int = conf.settings.get("changeup_body_indent", 2)
5051

5152
link_issues: bool = conf.settings.get("changeup_link_issues", True)
@@ -66,9 +67,13 @@ def changelog_message_builder_hook(
6667
)
6768

6869
if self.show_body and commit.body:
70+
body = str(commit.body)
71+
if self.hide_breaking and "BREAKING CHANGE:" in body:
72+
body = body.split("BREAKING CHANGE:")[0].strip()
73+
6974
msg += f"\n\n{' ' * self.body_indent}"
7075
body = ("\n\n" + (" " * self.body_indent)).join(
71-
[s.strip() for s in str(commit.body).split("\n") if s]
76+
[s.strip() for s in body.split("\n") if s]
7277
)
7378
msg += f"{body}"
7479

0 commit comments

Comments
 (0)