Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize commit messages on automerge #151

Merged
merged 2 commits into from Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion miss_islington/status_change.py
Expand Up @@ -99,7 +99,7 @@ async def merge_pr(gh, pr, sha, is_automerge=False):
async for commit in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/commits"):
if commit["sha"] == sha:
if is_automerge:
pr_commit_msg = pr["body"]
pr_commit_msg = util.normalize_message(pr["body"])
pr_title = f"{pr['title']} (GH-{pr_number})"
await gh.put(
f"/repos/python/cpython/pulls/{pr_number}/merge",
Expand Down
13 changes: 13 additions & 0 deletions miss_islington/util.py
Expand Up @@ -105,6 +105,19 @@ def normalize_title(title, body):
return title[:-1] + body[1:].partition("\r\n")[0]


def normalize_message(body):
"""Normalize the message body to make it commit-worthy.

Mostly this just means removing HTML comments, but also removes unwanted
leading or trailing whitespace.

Returns the normalized body.
"""
while "<!--" in body:
body = body[: body.index("<!--")] + body[body.index("-->") + 3 :]
return "\n\n" + body.strip()


# Copied over from https://github.com/python/bedevere
async def is_core_dev(gh, username):
"""Check if the user is a CPython core developer."""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_util.py
Expand Up @@ -55,6 +55,17 @@ def test_title_normalization():
assert util.normalize_title(title, body) == expected


def test_message_normalization():
message = "<!-- This is an HTML comment -->And this is the part we want"
assert util.normalize_message(message) == "\n\nAnd this is the part we want"

message = "<!-- HTML comment -->Part we want<!-- HTML comment 2 -->"
assert util.normalize_message(message) == "\n\nPart we want"

message = "\r\nParts <!--comment--> we want\r\nincluded"
assert util.normalize_message(message) == "\n\nParts we want\r\nincluded"


async def test_get_gh_participants_different_creator_and_committer():
gh = FakeGH(
getitem={
Expand Down