summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-10-14 15:49:23 -0500
committerGitHub <noreply@github.com>2022-10-14 15:49:23 -0500
commit813236e6ca265f15fe81b09a0a61feb3a3d0193b (patch)
tree87768fe14608498b23a66c49a0b14585016cab35
parent326c43632b94473083d8e78e71dca3c0ab3473f7 (diff)
parentba8099518353eafc95aa1e49c6b63cfe6ca1615a (diff)
downloadvyos-1x-813236e6ca265f15fe81b09a0a61feb3a3d0193b.tar.gz
vyos-1x-813236e6ca265f15fe81b09a0a61feb3a3d0193b.zip
Merge pull request #1588 from dmbaturin/pr-title-check
T4748: add a CI action to check pull request title format
-rw-r--r--.github/workflows/pull-request-message-check.yml23
-rwxr-xr-xscripts/check-pr-title-and-commit-messages.py44
2 files changed, 67 insertions, 0 deletions
diff --git a/.github/workflows/pull-request-message-check.yml b/.github/workflows/pull-request-message-check.yml
new file mode 100644
index 000000000..8c206a5ab
--- /dev/null
+++ b/.github/workflows/pull-request-message-check.yml
@@ -0,0 +1,23 @@
+---
+name: Check pull request message format
+
+on:
+ pull_request:
+ branches:
+ - current
+ - crux
+ - equuleus
+
+jobs:
+ check-pr-title:
+ name: Check pull request title
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/checkout@v2
+ timeout-minutes: 2
+ - name: Install the requests library
+ run: pip3 install requests
+ - name: Check the PR title
+ timeout-minutes: 2
+ run: |
+ ./scripts/check-pr-title-and-commit-messages.py '${{ github.event.pull_request.url }}'
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"])
+