servo: Merge #14450 - Implement tidy commit message test (from SijmenSchoon:master); r=Wafflespeanut
authorSijmen Schoon <me@sijmenschoon.nl>
Sat, 03 Dec 2016 14:15:22 -0800
changeset 340272 37bf28cc0b3321d0af8e509b8d8cdf28f53aa993
parent 340271 b1ff3ce9c6253045fda06ecbc6e1fc97dfb24c1f
child 340273 ca239fcfa931c379dfc327af16e37358379f0fda
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWafflespeanut
servo: Merge #14450 - Implement tidy commit message test (from SijmenSchoon:master); r=Wafflespeanut <!-- Please describe your changes on the following line: --> Makes tidy check commit messages since the latest merge, failing if one of them contains the string "WIP". I have written a test for my changes, although it is a bit hacky. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #14388. <!-- Either: --> - [x] These changes do not require tests because this would require playing with a new/existing git repo <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: da15790e41b9404845bec9ae4dcdc127d23fa8ca
servo/python/tidy/servo_tidy/tidy.py
--- a/servo/python/tidy/servo_tidy/tidy.py
+++ b/servo/python/tidy/servo_tidy/tidy.py
@@ -937,33 +937,51 @@ class LintRunner(object):
 def run_lint_scripts(only_changed_files=False, progress=True):
     runner = LintRunner(only_changed_files=only_changed_files, progress=progress)
     for path in config['lint-scripts']:
         runner.path = path
         for error in runner.check():
             yield error
 
 
+def check_commits(path='.'):
+    """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']
+    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')
+
+    raise StopIteration
+
+
 def scan(only_changed_files=False, progress=True):
     # check config file for errors
     config_errors = check_config_file(CONFIG_FILE_PATH)
     # check directories contain expected files
     directory_errors = check_directory_files(config['check_ext'])
     # standard checks
     files_to_check = filter_files('.', only_changed_files, progress)
     checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json)
     line_checking_functions = (check_license, check_by_line, check_toml, check_shell,
                                check_rust, check_spec, check_modeline)
     file_errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)
     # check dependecy licenses
     dep_license_errors = check_dep_license_errors(get_dep_toml_files(only_changed_files), progress)
     # other lint checks
     lint_errors = run_lint_scripts(only_changed_files, progress)
+    # check commits for WIP
+    commit_errors = check_commits()
     # chain all the iterators
-    errors = itertools.chain(config_errors, directory_errors, file_errors, dep_license_errors, lint_errors)
+    errors = itertools.chain(config_errors, directory_errors, file_errors, dep_license_errors, lint_errors,
+                             commit_errors)
 
     error = None
     for error in errors:
         colorama.init()
         print "\r\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
 
     print
     if error is None: