Skip to content

Commit c85b6df

Browse files
committed
Fix Labels extraction
1 parent 476aaea commit c85b6df

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

changelog/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,14 @@ def get_pr_details(github_config, owner, repo, pr_number):
182182
)
183183
)
184184

185-
return PullRequestDetails(body=pr_json["body"], labels=pr_json["labels"])
185+
labels = [label["name"] for label in pr_json["labels"]]
186+
187+
return PullRequestDetails(body=pr_json["body"], labels=labels)
186188

187189

188190
def extract_changelog(pr_body):
189191
"""Extracts the Changelog from the PR Body"""
190-
if pr_body == None:
192+
if pr_body is None:
191193
return None
192194
try:
193195
changelog_match = CHANGELOG_RE.search(pr_body)
@@ -279,12 +281,17 @@ def format_changes(github_config, owner, repo, prs, markdown=False):
279281
number = "[{number}]({link})".format(number=number, link=link)
280282

281283
pr_changelog_description = extract_changelog(extended_pr.details.body)
284+
285+
if len(extended_pr.details.labels or []) == 0:
286+
change_level = min(change_level, 2)
287+
282288
for label in extended_pr.details.labels or []:
283-
change_level = min(change_level, LABEL_LEVELS[label])
289+
change_level = min(change_level, LABEL_LEVELS.get(label) or 2)
290+
284291
lines.append(
285292
"- {description} {number}".format(
286293
description=pr_changelog_description
287-
if pr_changelog_description != None
294+
if pr_changelog_description is not None
288295
else pr.title,
289296
number=number,
290297
)

changelog/tests/test_changelog.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_get_pr_details(self, mock_requests_get):
186186
response.status_code = 200
187187
response.json.return_value = {
188188
"body": "Here comes the details of the PR",
189-
"labels": ["test", "BREAKING"],
189+
"labels": [{"name": "test"}, {"name": "BREAKING"}],
190190
}
191191
mock_requests_get.return_value = response
192192
result = get_pr_details(fake_github_config, "someone", "one-repo", "1")
@@ -284,7 +284,7 @@ def test_format_changes_uses_correct_base_url(self):
284284
github_config, "owner", "a-repo", prs, markdown=True
285285
)
286286
expected = [
287-
"PATCH RELEASE",
287+
"MINOR RELEASE",
288288
"- first [#1](https://github.company.com/owner/a-repo/pull/1)",
289289
"- second [#2](https://github.company.com/owner/a-repo/pull/2)",
290290
]
@@ -412,7 +412,7 @@ def test_generate_changelog(self, mock_requests_get):
412412
get_pr_details_response = mock.MagicMock()
413413
get_pr_details_response.status_code = 200
414414
get_pr_details_response.json.return_value = {
415-
"body": "My Title #10\n\nCHANGELOG: Specific ChangeLog description",
415+
"body": "My Title #10\n\nCHANGELOG: Specific Changelog",
416416
"labels": [],
417417
}
418418
responses.append(get_pr_details_response)
@@ -452,10 +452,10 @@ def test_generate_changelog(self, mock_requests_get):
452452
self.assertEqual(
453453
result,
454454
(
455-
"PATCH RELEASE\n"
455+
"MINOR RELEASE\n"
456456
"- My Title #5\n"
457457
"- Some title addresses bug #6\n"
458458
"- My Title #9\n"
459-
"- Specific ChangeLog description #10"
459+
"- Specific Changelog #10"
460460
),
461461
)

0 commit comments

Comments
 (0)