summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-command-op-templates11
-rwxr-xr-xscripts/build-command-templates10
-rwxr-xr-xscripts/check-pr-title-and-commit-messages.py44
3 files changed, 57 insertions, 8 deletions
diff --git a/scripts/build-command-op-templates b/scripts/build-command-op-templates
index d4515b8db..b008596dc 100755
--- a/scripts/build-command-op-templates
+++ b/scripts/build-command-op-templates
@@ -27,6 +27,7 @@ import copy
import functools
from lxml import etree as ET
+from textwrap import fill
# Defaults
validator_dir = "/opt/vyatta/libexec/validators"
@@ -123,13 +124,15 @@ def make_node_def(props, command):
node_def = ""
if "help" in props:
- node_def += "help: {0}\n".format(props["help"])
+ help = props["help"]
+ help = fill(help, width=64, subsequent_indent='\t\t\t')
+ node_def += f'help: {help}\n'
if "comp_help" in props:
- node_def += "allowed: {0}\n".format(props["comp_help"])
+ node_def += f'allowed: {props["comp_help"]}\n'
if command is not None:
- node_def += "run: {0}\n".format(command.text)
+ node_def += f'run: {command.text}\n'
if debug:
- print("The contents of the node.def file:\n", node_def)
+ print('Contents of the node.def file:\n', node_def)
return node_def
diff --git a/scripts/build-command-templates b/scripts/build-command-templates
index 876f5877c..c8ae83d9d 100755
--- a/scripts/build-command-templates
+++ b/scripts/build-command-templates
@@ -27,6 +27,7 @@ import copy
import functools
from lxml import etree as ET
+from textwrap import fill
# Defaults
@@ -130,6 +131,7 @@ def get_properties(p, default=None):
# DNS forwarding for instance has multiple defaults - specified as whitespace separated list
tmp = ', '.join(default.text.split())
help += f' (default: {tmp})'
+ help = fill(help, width=64, subsequent_indent='\t\t\t')
props["help"] = help
except:
pass
@@ -192,12 +194,12 @@ def get_properties(p, default=None):
# so we get to emulate it
comp_exprs = []
for i in lists:
- comp_exprs.append("echo \"{0}\"".format(i.text))
+ comp_exprs.append(f'echo "{i.text}"')
for i in paths:
- comp_exprs.append("/bin/cli-shell-api listNodes {0}".format(i.text))
+ comp_exprs.append(f'/bin/cli-shell-api listNodes {i.text}')
for i in scripts:
- comp_exprs.append("sh -c \"{0}\"".format(i.text))
- comp_help = " && ".join(comp_exprs)
+ comp_exprs.append(f'sh -c "{i.text}"')
+ comp_help = ' && echo " " && '.join(comp_exprs)
props["comp_help"] = comp_help
except:
props["comp_help"] = []
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..9801b7456
--- /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"])
+