Skip to content

Instantly share code, notes, and snippets.

@noahp
Created March 1, 2018 15:20
Show Gist options
  • Save noahp/25b1a2a8d13f3a071d9cc3ed4d634295 to your computer and use it in GitHub Desktop.
Save noahp/25b1a2a8d13f3a071d9cc3ed4d634295 to your computer and use it in GitHub Desktop.
Grab jira ticket from current branch and prefix commit message with it; .git/hooks/prepare-commit-msg
#!/usr/bin/env bash
# Try to yank the JIRA ticket number from the current branch and prefix the commit message with it
EXISTING_PREFIX=$(rg -e "[a-zA-Z]+-[0-9]+" $1)
if [[ ! -z $EXISTING_PREFIX ]]; then
exit
fi
JIRA_TICKET=$(git symbolic-ref --short HEAD | rg -o -e "[a-zA-Z]+-[0-9]+" | awk '{print toupper($0)": "}')
sed -i.bak -e "1s/^/$JIRA_TICKET/" $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment