Created
October 26, 2022 12:27
Prepend Ticket Number to Commit Message Hook
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 | |
COMMIT_FILE=$1 | |
COMMIT_MSG=$(cat $1) | |
JIRA_URL="≤JIRA_BASE_URL>/browse/" | |
if [ -z "$BRANCHES_TO_SKIP" ]; then | |
BRANCHES_TO_SKIP=(master develop) | |
fi | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | |
JIRA_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "[A-Z]+-[0-9]+") | |
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") | |
ALREADY_IN_MSG=$(grep -c "$JIRA_ID" $1) | |
echo ➡️" "$JIRA_URL$JIRA_ID | |
if [ -n "$CURRENT_BRANCH" ] && ! [[ "$BRANCH_EXCLUDED" -eq 1 ]] && ! [[ "$ALREADY_IN_MSG" -eq 1 ]]; then | |
sed -i.bak -e "1s/^/$JIRA_ID /" "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment