Skip to content

Commit df0042c

Browse files
committed
fix(changelog): rename message_hook -> changelog_message_builder_hook
1 parent aa2a9f9 commit df0042c

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

commitizen/changelog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def generate_tree_from_commits(
7373
changelog_pattern: str = defaults.bump_pattern,
7474
unreleased_version: Optional[str] = None,
7575
change_type_map: Optional[Dict[str, str]] = None,
76-
message_hook: Optional[Callable] = None,
76+
changelog_message_builder_hook: Optional[Callable] = None,
7777
) -> Iterable[Dict]:
7878
pat = re.compile(changelog_pattern)
7979
map_pat = re.compile(commit_parser)
@@ -120,8 +120,8 @@ def generate_tree_from_commits(
120120

121121
if change_type_map:
122122
change_type = change_type_map.get(change_type, change_type)
123-
if message_hook:
124-
parsed_message = message_hook(parsed_message, commit)
123+
if changelog_message_builder_hook:
124+
parsed_message = changelog_message_builder_hook(parsed_message, commit)
125125
changes[change_type].append(parsed_message)
126126
if message_body:
127127
parsed_message_body: Dict = message_body.groupdict()

commitizen/commands/changelog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def __call__(self):
6464
unreleased_version = self.unreleased_version
6565
changelog_meta: Dict = {}
6666
change_type_map: Optional[Dict] = self.change_type_map
67-
message_hook: Optional[Callable] = self.cz.message_hook
67+
changelog_message_builder_hook: Optional[
68+
Callable
69+
] = self.cz.changelog_message_builder_hook
6870
changelog_hook: Optional[Callable] = self.cz.changelog_hook
6971

7072
if not changelog_pattern or not commit_parser:
@@ -95,7 +97,7 @@ def __call__(self):
9597
changelog_pattern,
9698
unreleased_version,
9799
change_type_map=change_type_map,
98-
message_hook=message_hook,
100+
changelog_message_builder_hook=changelog_message_builder_hook,
99101
)
100102
changelog_out = changelog.render_changelog(tree)
101103

commitizen/cz/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class BaseCommitizen(metaclass=ABCMeta):
3131
change_type_map: Optional[Dict[str, str]] = None
3232

3333
# Executed per message parsed by the commitizen
34-
message_hook: Optional[Callable[[Dict, git.GitCommit], Dict]] = None
34+
changelog_message_builder_hook: Optional[
35+
Callable[[Dict, git.GitCommit], Dict]
36+
] = None
3537

3638
# Executed only at the end of the changelog generation
3739
changelog_hook: Optional[Callable[[str, Optional[str]], str]] = None

docs/customization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ You can customize it of course, and this are the variables you need to add to yo
142142
| `commit_parser` | `str` | NO | Regex which should provide the variables explained in the [changelog description][changelog-des] |
143143
| `changelog_pattern` | `str` | NO | Regex to validate the commits, this is useful to skip commits that don't meet your rulling standards like a Merge. Usually the same as bump_pattern |
144144
| `change_type_map` | `dict` | NO | Convert the title of the change type that will appear in the changelog, if a value is not found, the original will be provided |
145-
| `message_hook` | `method: (dict, git.GitCommit) -> dict` | NO | Customize with extra information your message output, like adding links, this function is executed per parsed commit. |
145+
| `changelog_message_builder_hook` | `method: (dict, git.GitCommit) -> dict` | NO | Customize with extra information your message output, like adding links, this function is executed per parsed commit. |
146146
| `changelog_hook` | `method: (full_changelog: str, partial_changelog: Optional[str]) -> str` | NO | Receives the whole and partial (if used incremental) changelog. Useful to send slack messages or notify a compliance department. Must return the full_changelog |
147147

148148
```python
@@ -160,7 +160,7 @@ class StrangeCommitizen(BaseCommitizen):
160160
"perf": "Performance improvements"
161161
}
162162

163-
def message_hook(self, parsed_message: dict, commit: git.GitCommit) -> dict:
163+
def changelog_message_builder_hook(self, parsed_message: dict, commit: git.GitCommit) -> dict:
164164
rev = commit.rev
165165
m = parsed_message["message"]
166166
parsed_message["message"] = f"{m} {rev}"

tests/test_changelog.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,19 @@ def test_render_changelog_with_change_type(gitcommits, tags):
715715
assert new_title in result
716716

717717

718-
def test_render_changelog_with_message_hook(gitcommits, tags):
719-
def message_hook(message: dict, _) -> dict:
718+
def test_render_changelog_with_changelog_message_builder_hook(gitcommits, tags):
719+
def changelog_message_builder_hook(message: dict, _) -> dict:
720720
message["message"] = f"{message['message']} [link](github.com/232323232)"
721721
return message
722722

723723
parser = defaults.commit_parser
724724
changelog_pattern = defaults.bump_pattern
725725
tree = changelog.generate_tree_from_commits(
726-
gitcommits, tags, parser, changelog_pattern, message_hook=message_hook
726+
gitcommits,
727+
tags,
728+
parser,
729+
changelog_pattern,
730+
changelog_message_builder_hook=changelog_message_builder_hook,
727731
)
728732
result = changelog.render_changelog(tree)
729733
assert "[link](github.com/232323232)" in result

0 commit comments

Comments
 (0)