Skip to content

Instantly share code, notes, and snippets.

@abuduba
Created December 16, 2019 21:42
Show Gist options
  • Save abuduba/9af4e0594b061b48d3cb4385bf7583a8 to your computer and use it in GitHub Desktop.
Save abuduba/9af4e0594b061b48d3cb4385bf7583a8 to your computer and use it in GitHub Desktop.
Prepend ticket number in the commit message
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
TICKET=$(git rev-parse --abbrev-ref HEAD | sed -E 's/([a-z]+\/)?([a-z]+-[0-9]+).*/[\2]/' | tr "[:lower:]" "[:upper:]" | grep -Eo '^\[([A-Z]+-)?\d+/]$')
if [[ "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi
echo "$TICKET $MESSAGE" > $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment