Created
July 24, 2024 02:00
-
-
Save Annath/4e48ae2f12fd3a9d61a7bca77c0ca183 to your computer and use it in GitHub Desktop.
Git pre-commit hook that automatically adds Jira ticket ID to your commit messages
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 | |
commit_msg_file=$1 | |
commit_msg=$(cat $commit_msg_file) | |
ticket_id=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?\w+\-[0-9]+' | grep -Eo '\w+\-[0-9]+' | tr "[:lower:]" "[:upper:]") | |
if [[ -z $ticket_id ]]; then | |
exit 0; | |
fi | |
case $commit_msg in | |
"fixup!"*) | |
;& | |
"amend!"*) | |
;& | |
"squash!"*) | |
;& | |
"$ticket_id"*) | |
exit 0; | |
;; | |
esac | |
echo "$ticket_id $commit_msg" > $commit_msg_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment