aboutsummaryrefslogtreecommitdiffstats
path: root/tools/validate-commit.py
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2020-08-18 16:00:32 -0700
committerGerald Combs <gerald@wireshark.org>2020-08-23 17:46:18 -0700
commit50550708ccc069ed127197761d400892e8dcde02 (patch)
tree2d138bc60d3bc12caa069fad57900cd9908f098f /tools/validate-commit.py
parent69ab0b00afd1a5ded9d86214bd1c2c134e028d3b (diff)
Add merge request jobs to GitLab CI and migrate commit validation.
Copy the Buildbot petri dish builder steps to corresponding GitLab CI jobs. Update validate-commit.py to look for old "Bug:" and "Ping-Bug:" references and have it call `git stripspace` directly. tools/commit-msg was specific to Gerrit, so remove it. Change-Id: Icbc54709052f44c941db9ad6a5dcf596292782a2
Diffstat (limited to 'tools/validate-commit.py')
-rwxr-xr-xtools/validate-commit.py32
1 files changed, 13 insertions, 19 deletions
diff --git a/tools/validate-commit.py b/tools/validate-commit.py
index 64d3e77893..417ae37688 100755
--- a/tools/validate-commit.py
+++ b/tools/validate-commit.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Verifies whether commit messages adhere to the standards.
# Checks the author name and email and invokes the tools/commit-msg script.
# Copy this into .git/hooks/post-commit
@@ -130,27 +130,21 @@ Please rewrite your commit message to our standards, matching this format:
Use paragraphs to improve readability. Limit each line to 80 characters.
''')
- fd, filename = tempfile.mkstemp()
- try:
- os.close(fd)
- with open(filename, 'w') as f:
- f.write(body)
-
- hook_script = os.path.join(tools_dir(), 'commit-msg')
- cmd = ['sh', hook_script, filename]
- subprocess.check_output(cmd, universal_newlines=True)
+ if any(line.startswith('Bug:') or line.startswith('Ping-Bug:') for line in old_lines):
+ sys.stderr.write('''
+To close an issue, use "Closes #1234" or "Fixes #1234" instead of "Bug: 1234".
+To reference an issue, use "related to #1234" instead of "Ping-Bug: 1234". See
+https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically
+for details.
+''')
+ return False
- with open(filename, 'r') as f:
- newbody = f.read()
+ try:
+ cmd = ['git', 'stripspace']
+ newbody = subprocess.check_output(cmd, input=body, universal_newlines=True)
except OSError as ex:
- print('Warning: unable to invoke commit-msg hook: %s' % (ex,))
+ print('Warning: unable to invoke git stripspace: %s' % (ex,))
return is_good
- except subprocess.CalledProcessError as ex:
- print('Bad commit message (reported by tools/commit-msg):')
- print(ex.output.strip())
- return False
- finally:
- os.unlink(filename)
if newbody != body:
new_lines = newbody.splitlines(True)
diff = difflib.unified_diff(old_lines, new_lines,