Created
April 18, 2022 02:14
-
-
Save sudosubin/656b99c63d80e9f185fc51b86a5d4eec to your computer and use it in GitHub Desktop.
How to auto prepend Jira ticket id to git commit msg?
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
#!/usr/bin/env bash | |
COMMIT_MSG_FILE=$1 | |
# COMMIT_SOURCE=$2 | |
# SHA1=$3 | |
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | |
if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "HEAD" ]; then | |
PREFIX_PATTERN="[A-Z]{2,5}-[0-9]+" | |
[[ $BRANCH_NAME =~ $PREFIX_PATTERN ]] | |
PREFIX=${BASH_REMATCH[0]} | |
PREFIX_IN_COMMIT=$(grep -c "\[$PREFIX\]" "$COMMIT_MSG_FILE") | |
if [[ -n "$PREFIX" ]] && ! [[ $PREFIX_IN_COMMIT -ge 1 ]]; then | |
sed -i.bak -e "1s~^~[$PREFIX] ~" "$COMMIT_MSG_FILE" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment