Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 948150d

Browse files
committed
feat(cz/customize): add jinja support to enhance template flexibility
#54
1 parent 4aeb28c commit 948150d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

commitizen/cz/customize/customize.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from jinja2 import Template
2+
13
from commitizen import defaults
24
from commitizen.cz.base import BaseCommitizen
35

@@ -24,8 +26,8 @@ def questions(self) -> list:
2426
return self.custom_config.get("questions")
2527

2628
def message(self, answers: dict) -> str:
27-
message_template = self.custom_config.get("message_template")
28-
return message_template.format(**answers)
29+
message_template = Template(self.custom_config.get("message_template"))
30+
return message_template.render(**answers)
2931

3032
def example(self) -> str:
3133
return self.custom_config.get("example")

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ colorama = "^0.4.1"
5151
termcolor = "^1.1"
5252
packaging = "^19.0"
5353
tomlkit = "^0.5.3"
54+
jinja2 = "^2.10.3"
5455

5556
[tool.poetry.dev-dependencies]
5657
ipython = "^7.2"

tests/test_cz_customize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def config():
1111
toml_str = """
1212
[tool.commitizen.customize]
1313
# message_template should follow the python string formatting spec
14-
message_template = "{change_type}: {message}"
14+
message_template = "{{change_type}}: {{message}}"
1515
example = "feature: this feature eanable customize through config file"
1616
schema = "<type>: <body>"
1717
bump_pattern = "^(break|new|fix|hotfix)"

0 commit comments

Comments
 (0)