aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Mathieson <martin.mathieson@keysight.com>2021-03-13 19:02:08 +0000
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-03-23 09:09:19 +0000
commit4981b10d0b5d459318e2678344ce9169190f23ff (patch)
treec613afe20b63b07eecf4cf7bf475642f0a9bf008
parent5177437f30941e592212412c33bc844e46f02862 (diff)
Add a commit-msg that may be installed to verify commit msg line length.
-rwxr-xr-xtools/commit-msg7
-rwxr-xr-xtools/validate-commit.py15
2 files changed, 20 insertions, 2 deletions
diff --git a/tools/commit-msg b/tools/commit-msg
new file mode 100755
index 0000000000..6b3052b3ad
--- /dev/null
+++ b/tools/commit-msg
@@ -0,0 +1,7 @@
+#!/bin/sh
+#
+# Validate the commit message.
+
+./tools/validate-commit.py --commitmsg $1
+
+
diff --git a/tools/validate-commit.py b/tools/validate-commit.py
index 8f0dde3a23..1c62561aa9 100755
--- a/tools/validate-commit.py
+++ b/tools/validate-commit.py
@@ -26,6 +26,7 @@ import urllib.request
parser = argparse.ArgumentParser()
parser.add_argument('commit', nargs='?', default='HEAD',
help='Commit ID to be checked (default %(default)s)')
+parser.add_argument('--commitmsg', help='commit-msg check', action='store')
def print_git_user_instructions():
@@ -115,7 +116,7 @@ def verify_body(body):
is_good = False
cleaned_subject = extract_subject(old_lines[0])
if len(cleaned_subject) > 80:
- # Note that this is currently also checked by the commit-msg hook.
+ # Note that this check is also invoked by the commit-msg hook.
print('Warning: keep lines in the commit message under 80 characters.')
is_good = False
if not is_good:
@@ -170,6 +171,7 @@ for details.
return is_good
+
def verify_merge_request():
# Not needed if/when https://gitlab.com/gitlab-org/gitlab/-/issues/23308 is fixed.
gitlab_api_pfx = "https://gitlab.com/api/v4"
@@ -210,11 +212,20 @@ def main():
args = parser.parse_args()
commit = args.commit
+ # If called from commit-msg script, just validate that part and return.
+ if args.commitmsg:
+ try:
+ with open(args.commitmsg) as f:
+ return 0 if verify_body(f.read()) else 1
+ except:
+ print("Couldn't verify body of message from file '", + args.commitmsg + "'");
+ return 1
+
+
if(os.getenv('CI_MERGE_REQUEST_EVENT_TYPE') == 'merge_train'):
print("If we were on the love train, people all over the world would be joining hands for this merge request.\nInstead, we're on a merge train so we're skipping commit validation checks. ")
return 0
-
cmd = ['git', 'show', '--no-patch',
'--format=%h%n%an%n%ae%n%B', commit, '--']
output = subprocess.check_output(cmd, universal_newlines=True)