From 1189a4527b65dbd3a842e27e2b2ec01295072b7a Mon Sep 17 00:00:00 2001 From: Aneesh Agrawal Date: Thu, 26 May 2016 22:07:42 -0400 Subject: [PATCH] Fix PR template and Reviewable from merge commits We recently added a PR template to the main Servo repo to smooth the contributing workflow. However, this template gets copied into homu's merge commit messages, generating a lot of noise in the commit logs. Use heuristics to strip both the PR template and the Reviewable footer. First, the main body of the PR template and the Reviewable footer are removed, as these are always the same (except for if the boxes are checked) and always at the bottom. The other part of the PR template is a header comment; some users replace it, while others leave it, and even though the message says to write below that line, some users write above it. So, simply remove it and trim any extra newlines. These heuristics should robustly leave the body untouched if the template is changed. This leaves a much cleaner commit message in the merge commit. Tested against an excerpt of recent commit messages from Servo. --- homu/main.py | 2 +- homu/utils.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/homu/main.py b/homu/main.py index 1754de18..2520d208 100644 --- a/homu/main.py +++ b/homu/main.py @@ -450,7 +450,7 @@ def create_merge(state, repo_cfg, branch, git_cfg): state.head_ref, '' if state.try_ else state.approved_by, state.title, - state.body, + utils.strip_pr_body(state.body), ) desc = 'Merge conflict' diff --git a/homu/utils.py b/homu/utils.py index afa3fa1a..11834e16 100644 --- a/homu/utils.py +++ b/homu/utils.py @@ -99,3 +99,16 @@ def retry_until(inner, fail, state): traceback.print_exception(*exc_info) fail(err) + + +def strip_pr_body(pr_body): + """ + Strip noisy parts of the Servo PR template from merge commits. + """ + # Strip most of the template and Reviewable + pr_footer = '\n---\n' + return stripped_body.replace(pr_header, '').strip()