I am using this script in the githook
ret = 1
with open(sys.argv) as msg:
res = re.match("^fix gh-[0-9]+.*$", msg.readline())
if res != None:
ret = 0
if (ret != 0):
print("Wrong commit message. Example: 'fix gh-1234 foo bar'")
Figured this out with the help of the Tower support team.
In my example I wasn't able to grab the argument (ie:
#!/usr/bin/python) by changing this to
#!/usr/bin/env bash I was able to get it. Now
$1 contains the argument.
#!/usr/bin/env bash # regex to validate in commit msg commit_regex='(gh-\d+|merge)' error_msg="Aborting commit. Your commit message is missing either a Github Issue ('GH-xxxx') or 'Merge'" if ! grep -iqE "$commit_regex" "$1"; then echo "$error_msg" >&2 exit 1 fi