Skip to content

Instantly share code, notes, and snippets.

@isyara
Last active December 17, 2021 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isyara/531930edeb03d914f8d50405ba087315 to your computer and use it in GitHub Desktop.
Save isyara/531930edeb03d914f8d50405ba087315 to your computer and use it in GitHub Desktop.
Git commit-msg hook to prepend jira id
COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
JIRA_PREFIX="ABCD"
# ex: feat/ABCD-1234-short-description
JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eio "^[a-z]+\/$JIRA_PREFIX-([0-9]+)" | sed 's/.*\///g')
#echo "=== Hook - commit-msg ==="
#echo " COMMIT_EDITMSG: $COMMIT_MSG"
#echo " BRANCH_NAME: $CURRENT_BRANCH"
#echo " JIRA_ID: $JIRA_ID"
#echo "========================"
# Check jira_id exist but not present in commit message
if [[ ! -z "$JIRA_ID" && ! $COMMIT_MSG =~ "$JIRA_ID" ]]; then
echo "[$JIRA_ID] $COMMIT_MSG" > $COMMIT_FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment