Last active
December 17, 2021 09:43
-
-
Save isyara/531930edeb03d914f8d50405ba087315 to your computer and use it in GitHub Desktop.
Git commit-msg hook to prepend jira id
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
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