Debian Codegraph @

docs/customization/config_file.md

raw
1 # Customize in configuration file
2
3 The basic steps are:
4
5 1. Define your custom committing or bumping rules in the configuration file.
6 2. Declare `name = "cz_customize"` in your configuration file, or add `-n cz_customize` when running Commitizen.
7 !!! warning
8 `cz_customize` is likely to be removed or renamed in the next major release.
9 This change is still under discussion; you can continue using `cz_customize` for now and follow [#1385](https://github.com/commitizen-tools/commitizen/issues/1385) for the rationale, options, and current status.
10
11 The following shows the **same configuration** in TOML, JSON, and YAML; use the format your project uses.
12
13 Example:
14
15 === "TOML"
16
17 ```toml title="pyproject.toml"
18 [tool.commitizen]
19 name = "cz_customize"
20
21 [tool.commitizen.customize]
22 message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
23 example = "feature: this feature enable customize through config file"
24 schema = "<type>: <body>"
25 schema_pattern = "(feature|bug fix):(\\s.*)"
26 bump_pattern = "^(break|new|fix|hotfix)"
27 bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
28 change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"]
29 info_path = "cz_customize_info.txt"
30 info = """
31 This is customized info
32 """
33 commit_parser = "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
34 changelog_pattern = "^(feature|bug fix)?(!)?"
35 change_type_map = {"feature" = "Feat", "bug fix" = "Fix"}
36
37 [[tool.commitizen.customize.questions]]
38 type = "list"
39 name = "change_type"
40 choices = [{value = "feature", name = "feature: A new feature."}, {value = "bug fix", name = "bug fix: A bug fix."}]
41 # choices = ["feature", "fix"] # short version
42 message = "Select the type of change you are committing"
43
44 [[tool.commitizen.customize.questions]]
45 type = "input"
46 name = "message"
47 message = "Body."
48
49 [[tool.commitizen.customize.questions]]
50 type = "confirm"
51 name = "show_message"
52 message = "Do you want to add body message in commit?"
53 ```
54
55 === "JSON"
56
57 ```json title=".cz.json"
58 {
59 "commitizen": {
60 "name": "cz_customize",
61 "customize": {
62 "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
63 "example": "feature: this feature enable customize through config file",
64 "schema": "<type>: <body>",
65 "schema_pattern": "(feature|bug fix):(\\s.*)",
66 "bump_pattern": "^(break|new|fix|hotfix)",
67 "bump_map": {
68 "break": "MAJOR",
69 "new": "MINOR",
70 "fix": "PATCH",
71 "hotfix": "PATCH"
72 },
73 "change_type_order": ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"],
74 "info_path": "cz_customize_info.txt",
75 "info": "This is customized info",
76 "commit_parser": "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?",
77 "changelog_pattern": "^(feature|bug fix)?(!)?",
78 "change_type_map": {"feature": "Feat", "bug fix": "Fix"},
79 "questions": [
80 {
81 "type": "list",
82 "name": "change_type",
83 "choices": [
84 {
85 "value": "feature",
86 "name": "feature: A new feature."
87 },
88 {
89 "value": "bug fix",
90 "name": "bug fix: A bug fix."
91 }
92 ],
93 "message": "Select the type of change you are committing"
94 },
95 {
96 "type": "input",
97 "name": "message",
98 "message": "Body."
99 },
100 {
101 "type": "confirm",
102 "name": "show_message",
103 "message": "Do you want to add body message in commit?"
104 }
105 ]
106 }
107 }
108 }
109 ```
110
111 === "YAML"
112
113 ```yaml title=".cz.yaml"
114 commitizen:
115 name: cz_customize
116 customize:
117 message_template: '{{change_type}}:{% if show_message %} {{message}}{% endif %}'
118 example: 'feature: this feature enable customize through config file'
119 schema: '<type>: <body>'
120 schema_pattern: '(feature|bug fix):(\\s.*)'
121 bump_pattern: '^(break|new|fix|hotfix)'
122 commit_parser: '^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?'
123 changelog_pattern: '^(feature|bug fix)?(!)?'
124 change_type_map:
125 feature: Feat
126 bug fix: Fix
127 bump_map:
128 break: MAJOR
129 new: MINOR
130 fix: PATCH
131 hotfix: PATCH
132 change_type_order: ['BREAKING CHANGE', 'feat', 'fix', 'refactor', 'perf']
133 info_path: cz_customize_info.txt
134 info: This is customized info
135 questions:
136 - type: list
137 name: change_type
138 choices:
139 - value: feature
140 name: 'feature: A new feature.'
141 - value: bug fix
142 name: 'bug fix: A bug fix.'
143 message: Select the type of change you are committing
144 - type: input
145 name: message
146 message: 'Body.'
147 - type: confirm
148 name: show_message
149 message: 'Do you want to add body message in commit?'
150 ```
151
152 ## Configuration File Options
153
154 | Parameter | Type | Default | Description |
155 | ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
156 | `questions` | `Questions` | `None` | Questions regarding the commit message. Detailed below. The type `Questions` is an alias to `Iterable[MutableMapping[str, Any]]` which is defined in `commitizen.defaults`. It expects a list of dictionaries. |
157 | `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow [Jinja2][jinja2] formatting specification, and all the variables in this template should be defined in `name` in `questions` |
158 | `example` | `str` | `""` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. |
159 | `schema` | `str` | `""` | (OPTIONAL) Show the schema used. Used by `cz schema`. |
160 | `schema_pattern` | `str` | `""` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
161 | `info_path` | `str` | `""` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. |
162 | `info` | `str` | `""` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. |
163 | `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) |
164 | `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) |
165 | `change_type_order` | `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]` |
166 | `commit_parser` | `str` | `None` | (OPTIONAL) Regex to extract information used in creating changelog. [See more][changelog-spec] |
167 | `changelog_pattern` | `str` | `None` | (OPTIONAL) Regex to understand which commits to include in the changelog |
168 | `change_type_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the type of the commit to a changelog entry |
169
170 [jinja2]: https://jinja.palletsprojects.com/en/2.10.x/
171 [changelog-spec]: https://commitizen-tools.github.io/commitizen/commands/changelog/
172
173 ### Detailed `questions` content
174
175 | Parameter | Type | Default | Description |
176 | ----------- | ------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
177 | `type` | `str` | `None` | The type of questions. Valid types: `list`, `select`, `input`, etc. The `select` type provides an interactive searchable list interface. [See More][different-question-types] |
178 | `name` | `str` | `None` | The key for the value answered by user. It's used in `message_template` |
179 | `message` | `str` | `None` | Detail description for the question. |
180 | `choices` | `list` | `None` | (OPTIONAL) The choices when `type = list` or `type = select`. Either use a list of values or a list of dictionaries with `name` and `value` keys. Keyboard shortcuts can be defined via `key`. See examples above. |
181 | `default` | `Any` | `None` | (OPTIONAL) The default value for this question. |
182 | `filter` | `str` | `None` | (OPTIONAL) Validator for user's answer. **(Work in Progress)** |
183 | `multiline` | `bool` | `False` | (OPTIONAL) Enable multiline support when `type = input`. |
184 | `use_search_filter` | `bool` | `False` | (OPTIONAL) Enable search/filter functionality for list/select type questions. This allows users to type and filter through the choices. |
185 | `use_jk_keys` | `bool` | `True` | (OPTIONAL) Enable/disable j/k keys for navigation in list/select type questions. Set to false if you prefer arrow keys only. |
186
187 [different-question-types]: https://github.com/tmbo/questionary#different-question-types
188
189 ### Shortcut keys
190
191 For a basic overview of `use_shortcuts` and how the default menu looks, see the [`use_shortcuts` option](../config/option.md#use_shortcuts).
192
193 #### `use_shortcuts` with `cz_customize`
194
195 When using `cz_customize`, enabling `use_shortcuts` lets you set an optional `key` for each list/select choice so that choice shows your chosen shortcut. Rules below.
196
197 Example:
198
199 ```toml title="pyproject.toml"
200 [tool.commitizen]
201 name = "cz_customize"
202 use_shortcuts = true
203
204 [tool.commitizen.customize]
205 message_template = "{{prefix}}: {{message}}"
206 schema = "<type>: <body>"
207 schema_pattern = "(feat|fix|docs|test):(\\s.*)"
208
209 [[tool.commitizen.customize.questions]]
210 type = "list"
211 name = "prefix"
212 message = "Select the type of change you are committing"
213 choices = [
214 { value = "feat", name = "feat: A new feature.", key = "f" },
215 { value = "fix", name = "fix: A bug fix.", key = "x" },
216 { value = "docs", name = "docs: Documentation only changes", key = "d" },
217 { value = "test", name = "test: Adding or correcting tests", key = "t" }
218 ]
219
220 [[tool.commitizen.customize.questions]]
221 type = "input"
222 name = "message"
223 message = "Commit body: "
224 ```
225
226 ![Menu with custom shortcut keys settings](../images/cli_interactive/shortcut_custom.gif)
227
228 **Rules for `key`**
229
230 | Rule | Description |
231 |------|-------------|
232 | Allowed | Lowercase `a`–`z` or digits `0`–`9` only |
233 | Uniqueness | Each `key` must be unique among all choices |
234 | Optional | Omit `key` to use default numeric order (1, 2, 3, …) |