Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 65d8268

Browse files
committed
refactor(changelog): rename category to change_type to fit 'keep a changelog'
1 parent 5bf5542 commit 65d8268

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

‎commitizen/changelog.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
from typing import Dict, Generator, Iterable, List
2323

2424
MD_VERSION_RE = r"^##\s(?P<version>[a-zA-Z0-9.+]+)\s?\(?(?P<date>[0-9-]+)?\)?"
25-
MD_CATEGORY_RE = r"^###\s(?P<category>[a-zA-Z0-9.+\s]+)"
25+
MD_CHANGE_TYPE_RE = r"^###\s(?P<change_type>[a-zA-Z0-9.+\s]+)"
2626
MD_MESSAGE_RE = r"^-\s(\*{2}(?P<scope>[a-zA-Z0-9]+)\*{2}:\s)?(?P<message>.+)"
2727
md_version_c = re.compile(MD_VERSION_RE)
28-
md_category_c = re.compile(MD_CATEGORY_RE)
28+
md_change_type_c = re.compile(MD_CHANGE_TYPE_RE)
2929
md_message_c = re.compile(MD_MESSAGE_RE)
3030

3131

@@ -83,8 +83,8 @@ def parse_md_version(md_version: str) -> Dict:
8383
return m.groupdict()
8484

8585

86-
def parse_md_category(md_category: str) -> Dict:
87-
m = md_category_c.match(md_category)
86+
def parse_md_change_type(md_change_type: str) -> Dict:
87+
m = md_change_type_c.match(md_change_type)
8888
if not m:
8989
return {}
9090
return m.groupdict()
@@ -97,31 +97,31 @@ def parse_md_message(md_message: str) -> Dict:
9797
return m.groupdict()
9898

9999

100-
def transform_category(category: str) -> str:
101-
_category_lower = category.lower()
100+
def transform_change_type(change_type: str) -> str:
101+
_change_type_lower = change_type.lower()
102102
for match_value, output in CATEGORIES:
103-
if re.search(match_value, _category_lower):
103+
if re.search(match_value, _change_type_lower):
104104
return output
105105
else:
106-
raise ValueError(f"Could not match a category with {category}")
106+
raise ValueError(f"Could not match a change_type with {change_type}")
107107

108108

109109
def generate_block_tree(block: List[str]) -> Dict:
110110
tree: Dict = {"commits": []}
111-
category = None
111+
change_type = None
112112
for line in block:
113113
if line.startswith("## "):
114-
category = None
114+
change_type = None
115115
tree = {**tree, **parse_md_version(line)}
116116
elif line.startswith("### "):
117-
result = parse_md_category(line)
117+
result = parse_md_change_type(line)
118118
if not result:
119119
continue
120-
category = transform_category(result.get("category", ""))
120+
change_type = transform_change_type(result.get("change_type", ""))
121121

122122
elif line.startswith("- "):
123123
commit = parse_md_message(line)
124-
commit["category"] = category
124+
commit["change_type"] = change_type
125125
tree["commits"].append(commit)
126126
else:
127127
print("it's something else: ", line)

‎commitizen/cz/conventional_commits/conventional_commits.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,6 @@ def info(self) -> str:
193193
def process_commit(self, commit: str) -> str:
194194
pat = re.compile(self.schema_pattern())
195195
m = re.match(pat, commit)
196+
if m is None:
197+
return ''
196198
return m.group(3).strip()

‎tests/test_changelog.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def test_read_changelog_blocks(existing_changelog_file):
102102
CATEGORIES_CASES: list = [
103103
("## 1.0.0 (2019年07月12日)", {}),
104104
("## 2.3.0a0", {}),
105-
("### Bug fixes", {"category": "Bug fixes"}),
106-
("### Features", {"category": "Features"}),
105+
("### Bug fixes", {"change_type": "Bug fixes"}),
106+
("### Features", {"change_type": "Features"}),
107107
("- issue in poetry add preventing the installation in py36", {}),
108108
]
109109
CATEGORIES_TRANSFORMATIONS: list = [
@@ -133,24 +133,24 @@ def test_parse_md_version(test_input, expected):
133133

134134

135135
@pytest.mark.parametrize("test_input,expected", CATEGORIES_CASES)
136-
def test_parse_md_category(test_input, expected):
137-
assert changelog.parse_md_category(test_input) == expected
136+
def test_parse_md_change_type(test_input, expected):
137+
assert changelog.parse_md_change_type(test_input) == expected
138138

139139

140140
@pytest.mark.parametrize("test_input,expected", CATEGORIES_TRANSFORMATIONS)
141-
def test_transform_category(test_input, expected):
142-
assert changelog.transform_category(test_input) == expected
141+
def test_transform_change_type(test_input, expected):
142+
assert changelog.transform_change_type(test_input) == expected
143143

144144

145145
@pytest.mark.parametrize("test_input,expected", MESSAGES_CASES)
146146
def test_parse_md_message(test_input, expected):
147147
assert changelog.parse_md_message(test_input) == expected
148148

149149

150-
def test_transform_category_fail():
150+
def test_transform_change_type_fail():
151151
with pytest.raises(ValueError) as excinfo:
152-
changelog.transform_category("Bugs")
153-
assert "Could not match a category" in str(excinfo.value)
152+
changelog.transform_change_type("Bugs")
153+
assert "Could not match a change_type" in str(excinfo.value)
154154

155155

156156
def test_generate_block_tree(existing_changelog_file):
@@ -162,16 +162,16 @@ def test_generate_block_tree(existing_changelog_file):
162162
{
163163
"scope": None,
164164
"message": "issue in poetry add preventing the installation in py36",
165-
"category": "fix",
165+
"change_type": "fix",
166166
},
167-
{"scope": "users", "message": "lorem ipsum apap", "category": "fix"},
167+
{"scope": "users", "message": "lorem ipsum apap", "change_type": "fix"},
168168
{
169169
"scope": None,
170170
"message": (
171171
"it is possible to specify a pattern to be matched "
172172
"in configuration files bump."
173173
),
174-
"category": "feat",
174+
"change_type": "feat",
175175
},
176176
],
177177
"version": "1.0.0",
@@ -191,23 +191,23 @@ def test_generate_full_tree(existing_changelog_file):
191191
"message": (
192192
"issue in poetry add preventing the installation in py36"
193193
),
194-
"category": "fix",
194+
"change_type": "fix",
195195
},
196-
{"scope": "users", "message": "lorem ipsum apap", "category": "fix"},
196+
{"scope": "users", "message": "lorem ipsum apap", "change_type": "fix"},
197197
{
198198
"scope": None,
199199
"message": (
200200
"it is possible to specify a pattern to be matched "
201201
"in configuration files bump."
202202
),
203-
"category": "feat",
203+
"change_type": "feat",
204204
},
205205
],
206206
"version": "1.0.0",
207207
"date": "2019年07月12日",
208208
},
209209
{
210-
"commits": [{"scope": None, "message": "holis", "category": "fix"}],
210+
"commits": [{"scope": None, "message": "holis", "change_type": "fix"}],
211211
"version": "0.9",
212212
"date": "2019年07月11日",
213213
},

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /