Last active
April 7, 2022 05:35
-
-
Save Nifled/40490167652da755152cac0b42713a6c to your computer and use it in GitHub Desktop.
Script to automatically add JIRA ticket reference as a prefix to commit messages. File must be within project's `/.git/hooks/`
This file contains 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/sh | |
# | |
# Commit hook to add a JIRA ticket reference as a prefix to any commit messages. | |
# NOTE: JIRA ticket number MUST be included in branch name or it does nothing... | |
# Doesn't make any specific checks, just does it. | |
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //') | |
REGEX_TICKET_ID='(SOFT-[0-9]{4})' # SOFT can be replaced by any JIRA team name | |
# Do the regex search | |
[[ $BRANCH_NAME =~ $REGEX_TICKET_ID ]] | |
# regex match | |
ticket_id=${BASH_REMATCH[1]} | |
# prefix the JIRA ticket id to commit message ($1) | |
echo "$ticket_id"': '$(cat "$1") > "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment