Created
September 17, 2013 23:09
-
-
Save sibljon/6601961 to your computer and use it in GitHub Desktop.
git commit-msg hook to prepend commit messages with a JIRA ticket number
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
#!/usr/bin/env ruby | |
# | |
# Jon Sibley, Sept 17 2013, based on this gist: https://gist.github.com/hakanensari/4194831 | |
# | |
# A minimal commit message hook that extracts a JIRA ticket number from the branch | |
# name and appends it to the commit message. | |
# | |
# The commit message remains unchanged if the branch name doesn't include a | |
# ticket number or the message already includes a reference to it. | |
# | |
# Let's assume you have a story that outlines that you want to deliver foo | |
# value. You start by checking out a branch: | |
# | |
# 123-deliver-foo-feature | |
# | |
# You commit a unit of work: | |
# | |
# Did bar | |
# | |
# This becomes: | |
# | |
# IOS-123 Did bar | |
# | |
branchname = `git name-rev --name-only HEAD 2>/dev/null`.strip | |
exit unless branchname.match(/^(\d+)/) | |
ticket = "#{$1}" | |
message_file = ARGV[0] | |
message = File.read(message_file) | |
# exit if message.include? "IOS-" + ticket | |
prepended_message = "IOS-#{ticket} " + message | |
File.open(message_file, 'w') { |f| f.write prepended_message } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment