Skip to content

Instantly share code, notes, and snippets.

@asalom
Created November 27, 2018 14:52
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 asalom/946b335900960f4985e168a20b7ace3f to your computer and use it in GitHub Desktop.
Save asalom/946b335900960f4985e168a20b7ace3f to your computer and use it in GitHub Desktop.
Prefix every commit with the JIRA ticket, given that the ticket can be found in the current branch's name
#!/bin/sh
COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+")
if [ ! -z "$JIRA_ID" ]; then
echo "[$JIRA_ID] $COMMIT_MSG" > $COMMIT_FILE
echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment