Skip to content

Instantly share code, notes, and snippets.

@kerasai
Created November 4, 2020 23:16
Show Gist options
  • Save kerasai/2af88c7a1f1a13520bcdaa6fbe157d06 to your computer and use it in GitHub Desktop.
Save kerasai/2af88c7a1f1a13520bcdaa6fbe157d06 to your computer and use it in GitHub Desktop.
Commit message validation for JIRA ticket number.
#!/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