TSK-1274: Added git hook, that validates git commits

This commit is contained in:
Tristan Eisermann 2020-06-05 16:27:10 +02:00 committed by Mustapha Zorgati
parent 18d6d33d24
commit 78570e8d32
1 changed files with 15 additions and 0 deletions

15
qa/hooks/commit-msg Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
MSG_FILE=$1
COMMIT_MESSAGE="$(cat $MSG_FILE)"
REGEX='^(TSK-[0-9]+):'
if [[ $COMMIT_MESSAGE =~ $REGEX ]]; then
TICKET=${BASH_REMATCH[1]}
RESULT=$(curl -s https://taskana.atlassian.net/rest/api/3/issue/$TICKET)
if [[ $RESULT =~ "errorMessages" ]]; then
echo -e "\033[0;31mERROR:\033[0m $TICKET is not a valid ticket number"
exit 1
fi
else
echo -e "\033[0;31mERROR:\033[0m Prefix Git commit messages with the ticket number, e.g. TSK-140: xyz..."
exit 1
fi