Created
November 4, 2020 23:16
-
-
Save kerasai/2af88c7a1f1a13520bcdaa6fbe157d06 to your computer and use it in GitHub Desktop.
Commit message validation for JIRA ticket number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
MSG=$(head -n 1 $1) | |
PATTERN='[A-Z]+-[0-9]+: .' | |
# Allows us to read user input below, assigns stdin to keyboard | |
exec < /dev/tty | |
if [[ ! $MSG =~ $PATTERN ]]; then | |
echo 'Commit message does not match the format "ABC-123: i did some stuff".' | |
read -p 'Continue anyways? [y/n]' yn | |
case $yn in | |
[Yy] ) break;; | |
* ) echo 'Commit aborted.'; exit 1;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment