|
| 1 | +Customizing commitizen is not hard at all. |
| 2 | + |
| 3 | +The basic steps are: |
| 4 | + |
| 5 | +1. Inheriting from `BaseCommitizen` |
| 6 | +2. Give a name to your rules. |
| 7 | +3. expose the class at the end of your file assigning it to `discover_this` |
| 8 | +4. Create a python package starting with `cz_` using `setup.py`, `poetry`, etc |
| 9 | + |
| 10 | + |
| 11 | +Check an [example](convcomms) on how to configure `BaseCommitizen`. |
| 12 | + |
1 | 13 | ## Custom commit rules
|
2 | 14 |
|
3 | 15 | Create a file starting with `cz_` for example `cz_jira.py`. This prefix
|
@@ -83,3 +95,35 @@ doing `pip install .`
|
83 | 95 | If you feel like it should be part of this repo, create a PR.
|
84 | 96 |
|
85 | 97 | [flask uses]: http://flask.pocoo.org/docs/0.12/extensiondev/
|
| 98 | + |
| 99 | +## Custom bump rules |
| 100 | + |
| 101 | +You need to define 2 parameters inside `BaseCommitizen`. |
| 102 | + |
| 103 | +| Parameter | Type | Default | Description | |
| 104 | +| --------- | ---- | ------- | ----------- | |
| 105 | +| `bump_pattern` | `str` | `None` | Regex to extract information from commit (subject and body) | |
| 106 | +| `bump_map` | `dict` | `None` | Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) | |
| 107 | + |
| 108 | +Let's see an exampple |
| 109 | + |
| 110 | +```python |
| 111 | +from commitizen.cz.base import BaseCommitizen |
| 112 | + |
| 113 | + |
| 114 | +class StrangeCommitizen(BaseCommitizen): |
| 115 | + bump_pattern = r"^(break|new|fix|hotfix)" |
| 116 | + bump_map = {"break": "MAJOR", "new": "MINOR"} |
| 117 | +``` |
| 118 | + |
| 119 | +As you can see we have ommitted `fix` and `hotfix`, both are gonna be picked up |
| 120 | +by the regex, but because they are not present in `bump_map` they will be mapped |
| 121 | +by default to `PATCH` |
| 122 | + |
| 123 | +That's it, your commitizen now supports custom rules and you can run |
| 124 | + |
| 125 | +```bash |
| 126 | +cz -n cz_strange bump |
| 127 | +``` |
| 128 | + |
| 129 | +[convcomms]: https://github.com/Woile/commitizen/blob/master/commitizen/cz/conventional_commits/conventional_commits.py |
0 commit comments