Check for merge commits with tidy

Increase merge commit check range under travis

Add comment on why travis workaround is necessary
This commit is contained in:
Sadman Kazi 2017-04-12 00:57:34 -04:00
parent ebc61bb2c3
commit cca3343c2e

View file

@ -1052,16 +1052,29 @@ def run_lint_scripts(only_changed_files=False, progress=True, stylo=False):
def check_commits(path='.'):
""" Checks if the test is being run under Travis CI environment
This is necessary since, after travis clones the branch for a PR, it merges
the branch against master, creating a merge commit. Hence, as a workaround,
we have to check if the second last merge commit is done by the author of
the pull request.
"""
is_travis = os.environ.get('TRAVIS') == 'true'
number_commits = '-n2' if is_travis else '-n1'
"""Gets all commits since the last merge."""
args = ['git', 'log', '-n1', '--merges', '--format=%H']
last_merge = subprocess.check_output(args, cwd=path).strip()
args = ['git', 'log', '{}..HEAD'.format(last_merge), '--format=%s']
args = ['git', 'log', number_commits, '--merges', '--format=%H:%an']
# last_merge stores both the commit hash and the author name of the last merge in the output
last_merge_hash, last_merge_author = subprocess.check_output(args, cwd=path).strip().splitlines()[-1].split(':')
args = ['git', 'log', '{}..HEAD'.format(last_merge_hash), '--format=%s']
commits = subprocess.check_output(args, cwd=path).lower().splitlines()
for commit in commits:
# .split() to only match entire words
if 'wip' in commit.split():
yield ('.', 0, 'no commits should contain WIP')
yield (':', ':', 'no commits should contain WIP')
if last_merge_author != 'bors-servo':
yield (':', ':', 'no merge commits allowed, please rebase your commits over the upstream master branch')
raise StopIteration