Last active
May 24, 2018 23:01
-
-
Save chandeeland/950cb4570ee78fa93516241bd47b6fb9 to your computer and use it in GitHub Desktop.
this will try to detect your Jira ticket id from your branch name and insert it into your commit message
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/bash | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
if [ -z "$BRANCH_NAME" ]; then | |
exit 0 | |
fi | |
if [ "master" = "$BRANCH_NAME" ]; then | |
exit 0 | |
fi | |
IS_A_RELEASE_BRANCH=$(printf "%s\n" "${BRANCH_NAME}" | grep -c "^release") | |
if [ $IS_A_RELEASE_BRANCH -eq 1 ]; then | |
exit 0 | |
fi | |
JIRA_ISSUE_ID=$(printf "%s" ${BRANCH_NAME} | sed -E 's/^[^\/]*\/?([A-Za-z]{2}-[0-9]+).*/\1/g' ) | |
if [ -n "$JIRA_ISSUE_ID" ]; then | |
sed -i.bak -E "1s/^(\[$JIRA_ISSUE_ID\] )?/[$JIRA_ISSUE_ID] /" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dont forget to
chmod 755 .git/hooks/prepare-commit-msg