Skip to content

Instantly share code, notes, and snippets.

@KeyboardCowboy
Created April 21, 2015 23:10
Show Gist options
  • Save KeyboardCowboy/8694a9caeb3702d6505c to your computer and use it in GitHub Desktop.
Save KeyboardCowboy/8694a9caeb3702d6505c to your computer and use it in GitHub Desktop.
Blastr Git Commit Message Hook for Jira Comments
#!/bin/bash
# INSTRUCTIONS
#
# 1. Copy .git/hooks/commit-msg.sample to .git/hooks/commit-msg
# 2. Replace the contents of commit-msg with this file
#
# Automatically add ticket numbers to commit messages using branch names.
#
# Branches should be in the format [username]-[issue #]-[short-desc]
#
# Ex. kc-8-pub7-update
# Jira project name
JIRA_PROJ="BLREDES"
# Get the branch name
NAME=$(git branch | grep '*' | sed 's/* //')
# Grab the ticket string out of the branch name.
TICKET=$(echo $NAME | grep -o '\-[0-9]*\-')
# Strip off the hyphens to get the issue number.
TICKET="${TICKET:1:${#TICKET}-2}"
# Prepend the ticket number to the commit message with the proper JIRA format.
echo "$JIRA_PROJ-$TICKET #comment "$(cat "$1") > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment