Skip to content

Commit 64aa55e

Browse files
authored
Merge pull request #1 from TheNomet/feat/addional_config_ch
Feat/addional config ch
2 parents 976d5d2 + d28c095 commit 64aa55e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

commitizen/cz/customize/customize.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ def __init__(self, config: BaseConfig):
3737
if custom_change_type_order:
3838
self.change_type_order = custom_change_type_order
3939

40+
commit_parser = self.custom_settings.get("commit_parser")
41+
if commit_parser:
42+
self.commit_parser = commit_parser
43+
44+
changelog_pattern = self.custom_settings.get("changelog_pattern")
45+
if changelog_pattern:
46+
self.changelog_pattern = changelog_pattern
47+
48+
change_type_map = self.custom_settings.get("change_type_map")
49+
if change_type_map:
50+
self.change_type_map = change_type_map
51+
4052
def questions(self) -> List[Dict[str, Any]]:
4153
return self.custom_settings.get("questions")
4254

docs/customization.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ info_path = "cz_customize_info.txt"
2828
info = """
2929
This is customized info
3030
"""
31+
commit_parser = "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
32+
changelog_pattern = "^(feature|bug fix)?(!)?"
33+
change_type_map = {"feature" = "Feat", "bug fix" = "Fix"}
3134

3235
[[tool.commitizen.customize.questions]]
3336
type = "list"
@@ -68,6 +71,9 @@ The equivalent example for a json config file:
6871
"change_type_order": ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"],
6972
"info_path": "cz_customize_info.txt",
7073
"info": "This is customized info",
74+
"commit_parser": "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?",
75+
"changelog_pattern": "^(feature|bug fix)?(!)?",
76+
"change_type_map": {"feature": "Feat", "bug fix": "Fix"},
7177
"questions": [
7278
{
7379
"type": "list",
@@ -111,6 +117,11 @@ commitizen:
111117
schema: "<type>: <body>"
112118
schema_pattern: "(feature|bug fix):(\\s.*)"
113119
bump_pattern: "^(break|new|fix|hotfix)"
120+
commit_parser: "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?",
121+
changelog_pattern: "^(feature|bug fix)?(!)?",
122+
change_type_map:
123+
feature: Feat
124+
bug fix: Fix
114125
bump_map:
115126
break: MAJOR
116127
new: MINOR
@@ -150,8 +161,12 @@ commitizen:
150161
| `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) |
151162
| `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) |
152163
| `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"]` |
164+
| `commit_parser` | `str` | `None` | (OPTIONAL) Regex to extract information used in creating changelog. [See more][changelog-spec] |
165+
| `changelog_pattern` | `str` | `None` | (OPTIONAL) Regex to understand which commits to include in the changelog |
166+
| `change_type_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the type of the commit to a changelog entry |
153167

154168
[jinja2]: https://jinja.palletsprojects.com/en/2.10.x/
169+
[changelog-spec]: https://commitizen-tools.github.io/commitizen/changelog/
155170
#### Detailed `questions` content
156171

157172
| Parameter | Type | Default | Description |
@@ -170,7 +185,7 @@ commitizen:
170185
When the [`use_shortcuts`](https://commitizen-tools.github.io/commitizen/config/#settings) config option is enabled, commitizen can show and use keyboard shortcuts to select items from lists directly.
171186
For example, when using the `cz_conventional_commits` commitizen template, shortcut keys are shown when selecting the commit type. Unless otherwise defined, keyboard shortcuts will be numbered automatically.
172187
To specify keyboard shortcuts for your custom choices, provide the shortcut using the `key` parameter in dictionary form for each choice you would like to customize.
173-
188+
174189
## 2. Customize through customizing a class
175190

176191
The basic steps are:

tests/test_cz_customize.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
example = "feature: this feature enable customize through config file"
1111
schema = "<type>: <body>"
1212
schema_pattern = "(feature|bug fix):(\\s.*)"
13+
commit_parser = "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
14+
changelog_pattern = "^(feature|bug fix)?(!)?"
15+
change_type_map = {"feature" = "Feat", "bug fix" = "Fix"}
1316
1417
bump_pattern = "^(break|new|fix|hotfix)"
1518
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
@@ -57,6 +60,9 @@
5760
"fix": "PATCH",
5861
"hotfix": "PATCH"
5962
},
63+
"commit_parser": "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?",
64+
"changelog_pattern": "^(feature|bug fix)?(!)?",
65+
"change_type_map": {"feature": "Feat", "bug fix": "Fix"},
6066
"change_type_order": ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"],
6167
"info": "This is a customized cz.",
6268
"questions": [
@@ -363,3 +369,18 @@ def test_info_with_info_path(tmpdir, config_info):
363369
def test_info_without_info(config_without_info):
364370
cz = CustomizeCommitsCz(config_without_info)
365371
assert cz.info() is None
372+
373+
374+
def test_commit_parser(config):
375+
cz = CustomizeCommitsCz(config)
376+
assert cz.commit_parser == "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
377+
378+
379+
def test_changelog_pattern(config):
380+
cz = CustomizeCommitsCz(config)
381+
assert cz.changelog_pattern == "^(feature|bug fix)?(!)?"
382+
383+
384+
def test_change_type_map(config):
385+
cz = CustomizeCommitsCz(config)
386+
assert cz.change_type_map == {"feature": "Feat", "bug fix": "Fix"}

0 commit comments

Comments
 (0)