Skip to content

Instantly share code, notes, and snippets.

@muhrifqii
Last active May 15, 2024 04:36
Show Gist options
  • Save muhrifqii/a8a4e140040f54b3452ef14b9c31d9c3 to your computer and use it in GitHub Desktop.
Save muhrifqii/a8a4e140040f54b3452ef14b9c31d9c3 to your computer and use it in GitHub Desktop.
git hooks to add jira ticket number as prefix in commit message. put it on .git/hooks/prepare-commit-msg
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
TICKET="$(git rev-parse --abbrev-ref HEAD | grep -Eo '(\w+/)?(\w+-)?[0-9]+' | tail -1 | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]") :"
if [[ $TICKET == " : " || "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi
echo "$TICKET $MESSAGE" > $FILE
@muhrifqii
Copy link
Author

JIRA TICKET COMMIT MESSAGE PREFFIX

this will change the branch name of:

  • hotfix/key-100_some-name into KEY-100 commit msg prefix
  • feature/uwu-2212_name into UWU-2212 commit msg prefix
  • release/cab-3/cab-4_release1 into CAB-4 commit msg prefix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment