Skip to content

Instantly share code, notes, and snippets.

@Stoffo
Created October 26, 2022 12:27
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 Stoffo/d5885c2a5d43395bb99365e95a98f81b to your computer and use it in GitHub Desktop.
Save Stoffo/d5885c2a5d43395bb99365e95a98f81b to your computer and use it in GitHub Desktop.
Prepend Ticket Number to Commit Message Hook
#!/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