summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2022-10-12 17:46:31 +0100
committerDaniil Baturin <daniil@baturin.org>2022-10-13 21:30:50 +0100
commitba8099518353eafc95aa1e49c6b63cfe6ca1615a (patch)
tree8cb1ddc8d613aebc4831033d3360f56aad640d50 /scripts
parent06d6386e5d9fb9812b23032516bbdc938dcc4a9f (diff)
downloadvyos-1x-ba8099518353eafc95aa1e49c6b63cfe6ca1615a.tar.gz
vyos-1x-ba8099518353eafc95aa1e49c6b63cfe6ca1615a.zip
ci: T4748: add a CI action to check pull request title
and commit messages format
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check-pr-title-and-commit-messages.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/check-pr-title-and-commit-messages.py b/scripts/check-pr-title-and-commit-messages.py
new file mode 100755
index 000000000..c30c3ef1f
--- /dev/null
+++ b/scripts/check-pr-title-and-commit-messages.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+import requests
+from pprint import pprint
+
+# Use the same regex for PR title and commit messages for now
+title_regex = r'^(([a-zA-Z]+:\s)?)T\d+:\s+[^\s]+.*'
+commit_regex = title_regex
+
+def check_pr_title(title):
+ if not re.match(title_regex, title):
+ print("PR title '{}' does not match the required format!".format(title))
+ print("Valid title example: T99999: make IPsec secure")
+ sys.exit(1)
+
+def check_commit_message(title):
+ if not re.match(commit_regex, title):
+ print("Commit title '{}' does not match the required format!".format(title))
+ print("Valid title example: T99999: make IPsec secure")
+ sys.exit(1)
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ print("Please specify pull request URL!")
+ sys.exit(1)
+
+ # Get the pull request object
+ pr = requests.get(sys.argv[1]).json()
+ if "title" not in pr:
+ print("Did not receive a valid pull request object, please check the URL!")
+ sys.exit(1)
+
+ check_pr_title(pr["title"])
+
+ # Get the list of commits
+ commits = requests.get(pr["commits_url"]).json()
+ for c in commits:
+ # Retrieve every individual commit and check its title
+ co = requests.get(c["url"]).json()
+ check_commit_message(co["commit"]["message"])
+