Created
August 13, 2020 16:42
-
-
Save Tethik/1127a48c4521e0c396f45cb4ebd65b49 to your computer and use it in GitHub Desktop.
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/bash | |
TICKET_REGEX="^(([a-zA-Z]+)\-([0-9]+))" | |
BRANCH_REGEX="^(feature|chore)\/(([a-zA-Z]+)\-([0-9]+))\-.*" | |
branch=$(git branch --show-current) | |
if [[ $branch =~ $BRANCH_REGEX ]]; then | |
ticket="${BASH_REMATCH[2]}" | |
content=$(cat $1 | grep -v '^#') | |
if [[ -z "${content// }" ]]; then | |
exit 0 # empty message | |
fi | |
if [[ $content =~ $TICKET_REGEX ]]; then | |
if [[ ${BASH_REMATCH[1]} -ne $ticket ]]; then | |
echo "Warning: Different Ticket ID '${BASH_REMATCH[1]}' (vs '${ticket}') already prepended to commit message" | |
exit 1 | |
else | |
exit 0 # already prepended | |
fi | |
fi | |
echo "${ticket} ${content}" > $1 | |
echo "Ticket ID '${ticket}' prepended to commit message" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment