-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathcustomize.py
99 lines (78 loc) · 3.4 KB
/
customize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from __future__ import annotations
from commitizen.cz.conventional_commits import ConventionalCommitsCz
try:
from jinja2 import Template
except ImportError:
from string import Template # type: ignore
from commitizen.config import BaseConfig
from commitizen.defaults import Questions
from commitizen.exceptions import MissingCzCustomizeConfigError
__all__ = ["CustomizeCommitsCz"]
class CustomizeCommitsCz(ConventionalCommitsCz):
def __init__(self, config: BaseConfig):
super().__init__(config)
if "customize" not in self.config.settings:
raise MissingCzCustomizeConfigError()
self.custom_settings = self.config.settings["customize"]
custom_bump_pattern = self.custom_settings.get("bump_pattern")
if custom_bump_pattern:
self.bump_pattern = custom_bump_pattern
custom_bump_map = self.custom_settings.get("bump_map")
if custom_bump_map:
self.bump_map = custom_bump_map
custom_bump_map_major_version_zero = self.custom_settings.get(
"bump_map_major_version_zero"
)
if custom_bump_map_major_version_zero:
self.bump_map_major_version_zero = custom_bump_map_major_version_zero
custom_change_type_order = self.custom_settings.get("change_type_order")
if custom_change_type_order:
self.change_type_order = custom_change_type_order
commit_parser = self.custom_settings.get("commit_parser")
if commit_parser:
self.commit_parser = commit_parser
changelog_pattern = self.custom_settings.get("changelog_pattern")
if changelog_pattern:
self.changelog_pattern = changelog_pattern
change_type_map = self.custom_settings.get("change_type_map")
if change_type_map:
self.change_type_map = change_type_map
def questions(self) -> Questions:
custom_questions = self.custom_settings.get("questions")
if custom_questions:
return custom_questions
return super().questions()
def message(self, answers: dict) -> str:
custom_message = self.custom_settings.get("message_template")
if custom_message:
message_template = Template(custom_message)
if getattr(Template, "substitute", None):
return message_template.substitute(**answers) # type: ignore
else:
return message_template.render(**answers)
return super().message(answers)
def example(self) -> str:
custom_example = self.custom_settings.get("example")
if custom_example:
return custom_example
return super().example()
def schema_pattern(self) -> str:
custom_schema_pattern = self.custom_settings.get("schema_pattern")
if custom_schema_pattern:
return custom_schema_pattern
return super().schema_pattern()
def schema(self) -> str:
custom_schema = self.custom_settings.get("schema")
if custom_schema:
return custom_schema
return super().schema()
def info(self) -> str:
info_path = self.custom_settings.get("info_path")
info = self.custom_settings.get("info")
if info_path:
with open(info_path, encoding=self.config.settings["encoding"]) as f:
content = f.read()
return content
elif info:
return info
return super().info()