Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit edaba14

Browse files
committed
docs: add info about creating hooks
1 parent 80c5e84 commit edaba14

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

‎docs/changelog.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,15 @@ Benefits:
124124
cz changelog --incremental
125125
```
126126
127-
## TODO
127+
## Hooks
128128
129-
- [ ] support for hooks: this would allow introduction of custom information in the commiter, like a github or jira url. Eventually we could build a `CzConventionalGithub`, which would add links to commits
130-
- [x] support for map: allow the usage of a `change_type` mapper, to convert from feat to feature for example.
129+
Supported hook methods:
130+
131+
- per parsed message: useful to add links
132+
- end of changelog generation: useful to send slack or chat message, or notify another department
133+
134+
Read more about hooks in the [customization page][customization]
131135
132136
[keepachangelog]: https://keepachangelog.com/
133137
[semver]: https://semver.org/
138+
[customization]: ./customization.md

‎docs/customization.md‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,41 @@ cz -n cz_strange bump
137137
The changelog generator should just work in a very basic manner without touching anything.
138138
You can customize it of course, and this are the variables you need to add to your custom `BaseCommitizen`.
139139

140-
| Parameter | Type | Required | Description |
141-
| ------------------- | --------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
142-
| `commit_parser` | `str` | NO | Regex which should provide the variables explained in the [changelog description][changelog-des] |
143-
| `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 |
144-
| `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. |
140+
| Parameter | Type | Required | Description |
141+
| ------------------- | ------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
142+
| `commit_parser` | `str` | NO | Regex which should provide the variables explained in the [changelog description][changelog-des] |
143+
| `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 |
144+
| `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. |
146+
| `changelog_hook` | `method: (full_changelog: str, partial_changelog: Optional[str]) -> None` | NO | Receives the whole and partial (if used incremental) changelog. Useful to send slack messages or notify a compliance department. |
147+
148+
```python
149+
from commitizen.cz.base import BaseCommitizen
150+
import chat
151+
import compliance
152+
153+
class StrangeCommitizen(BaseCommitizen):
154+
changelog_pattern = r"^(break|new|fix|hotfix)"
155+
commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?"
156+
change_type_map = {
157+
"feat": "Features",
158+
"fix": "Bug Fixes",
159+
"refactor": "Code Refactor",
160+
"perf": "Performance improvements"
161+
}
162+
163+
def message_hook(self, parsed_message: dict, commit: git.GitCommit) -> dict:
164+
rev = commit.rev
165+
m = parsed_message["message"]
166+
parsed_message["message"] = f"{m}{rev}"
167+
return parsed_message
168+
169+
def changelog_hook(self, full_changelog: str, partial_changelog: Optional[str]) -> None
170+
if partial_changelog:
171+
chat.room("#commiters").notify(partial_changelog)
172+
if full_changelog:
173+
compliance.send(full_changelog)
174+
```
146175

147176
[changelog-des]: ./changelog.md#description
148177

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /