Skip to content

Commit c607cce

Browse files
zwareMariatta
authored andcommitted
Normalize commit messages on automerge (#151)
Remove HTML comments and unwanted leading and trailing whitespace from the commit message. Fixes #150
1 parent 3215042 commit c607cce

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

miss_islington/status_change.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def merge_pr(gh, pr, sha, is_automerge=False):
9999
async for commit in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/commits"):
100100
if commit["sha"] == sha:
101101
if is_automerge:
102-
pr_commit_msg = pr["body"]
102+
pr_commit_msg = util.normalize_message(pr["body"])
103103
pr_title = f"{pr['title']} (GH-{pr_number})"
104104
await gh.put(
105105
f"/repos/python/cpython/pulls/{pr_number}/merge",

miss_islington/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ def normalize_title(title, body):
105105
return title[:-1] + body[1:].partition("\r\n")[0]
106106

107107

108+
def normalize_message(body):
109+
"""Normalize the message body to make it commit-worthy.
110+
111+
Mostly this just means removing HTML comments, but also removes unwanted
112+
leading or trailing whitespace.
113+
114+
Returns the normalized body.
115+
"""
116+
while "<!--" in body:
117+
body = body[: body.index("<!--")] + body[body.index("-->") + 3 :]
118+
return "\n\n" + body.strip()
119+
120+
108121
# Copied over from https://github.com/python/bedevere
109122
async def is_core_dev(gh, username):
110123
"""Check if the user is a CPython core developer."""

tests/test_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ def test_title_normalization():
5555
assert util.normalize_title(title, body) == expected
5656

5757

58+
def test_message_normalization():
59+
message = "<!-- This is an HTML comment -->And this is the part we want"
60+
assert util.normalize_message(message) == "\n\nAnd this is the part we want"
61+
62+
message = "<!-- HTML comment -->Part we want<!-- HTML comment 2 -->"
63+
assert util.normalize_message(message) == "\n\nPart we want"
64+
65+
message = "\r\nParts <!--comment--> we want\r\nincluded"
66+
assert util.normalize_message(message) == "\n\nParts we want\r\nincluded"
67+
68+
5869
async def test_get_gh_participants_different_creator_and_committer():
5970
gh = FakeGH(
6071
getitem={

0 commit comments

Comments
 (0)