summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2024-04-13 08:18:45 +0000
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-04-13 10:16:00 +0000
commit0f1f8f00bb79f1949025d313f8ad19c566aa84f9 (patch)
tree6b2cc9d5eb47ece9023fb3605e9ba23a0c72fd37
parentaa4667ab3dad6d30805b2d703700372f8a0184d2 (diff)
downloadvyos-build-0f1f8f00bb79f1949025d313f8ad19c566aa84f9.tar.gz
vyos-build-0f1f8f00bb79f1949025d313f8ad19c566aa84f9.zip
T6238: Check poll request title action requires the python script
The `check-pr-title-and-commit-messages.py` that used for the action is not exists. Add this script. (cherry picked from commit 06d12a527eb6601e67c36a740c81974f64752abe)
-rwxr-xr-xscripts/check-pr-title-and-commit-messages.py54
1 files changed, 54 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 00000000..8fe3ca79
--- /dev/null
+++ b/scripts/check-pr-title-and-commit-messages.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+import time
+
+import requests
+
+# 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(f"PR title '{title}' does not match the required format!")
+ 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 '{title}' does not match the required format!")
+ 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)
+
+ # There seems to be a race condition that causes this scripts to receive
+ # an incomplete PR object that is missing certain fields,
+ # which causes temporary CI failures that require re-running the script
+ #
+ # It's probably better to add a small delay to prevent that
+ time.sleep(5)
+
+ # Get the pull request object
+ pr = requests.get(sys.argv[1]).json()
+ if "title" not in pr:
+ print("The PR object does not have a title field!")
+ 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"])