Skip to content

Instantly share code, notes, and snippets.

@masterzen
Created April 20, 2017 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masterzen/dbff4d9e73a3346ca32ea54ea596acb8 to your computer and use it in GitHub Desktop.
Save masterzen/dbff4d9e73a3346ca32ea54ea596acb8 to your computer and use it in GitHub Desktop.
JIRA templated commit message
#!/bin/sh
set -e
# We don't want to mess with the commit message if no template has been
# defined, or if we're doing a special commit (rebase, merge, amend, ...)
[[ $2 != "template" ]] && exit 0
ticket_id=$(git symbolic-ref -q --short HEAD | perl -ne 'print if s,.*\b([a-z]+-[0-9]+).*$,\U\1,i');
if [ ! $ticket_id ]; then
# Couldn't get a matching ticket ID, so remove the template from the
# preformatted commit message.
template=$(git config --get commit.template)
lines=$(wc -l $template | cut -d' ' -f1 -)
sed -i'' -e"1,$lines d" "$1"
exit 0;
fi
# The magic happens right here. Witness!
base_url="https://daysofwonder.atlassian.net/browse/"
sed -i'' -e"" -e"s,<ticket-id>,${ticket_id} ," -e"s,<ticket-url>,${base_url}${ticket_id}," "$1"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment