Created
April 20, 2017 15:01
-
-
Save masterzen/dbff4d9e73a3346ca32ea54ea596acb8 to your computer and use it in GitHub Desktop.
JIRA templated commit message
This file contains 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/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