Skip to content

Instantly share code, notes, and snippets.

@Annath
Created July 24, 2024 02:00
Show Gist options
  • Save Annath/4e48ae2f12fd3a9d61a7bca77c0ca183 to your computer and use it in GitHub Desktop.
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
#!/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