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