Skip to content

Instantly share code, notes, and snippets.

@zph
Created April 23, 2014 18:55
Show Gist options
  • Select an option

  • Save zph/11228092 to your computer and use it in GitHub Desktop.

Select an option

Save zph/11228092 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
branch_name = `git rev-parse --abbrev-ref HEAD`.chomp
DIVIDERS = %r{[-|_|/|\/]}
parts = branch_name.match(/(?<initials>.+)#{DIVIDERS}(?<number>\d{3,})#{DIVIDERS}(?<description>.*)/)
begin
INITIALS = parts[:initials].split(DIVIDERS).join("/").upcase
PIVOTAL_NUMBER = parts[:number]
DESCRIPTION = parts[:description].gsub(/#{DIVIDERS}/, ' ')
rescue
exit(0)
end
commit_message = <<MSG
[#{INITIALS}] [#{PIVOTAL_NUMBER}] #{DESCRIPTION}
Pivotal Story: https://www.pivotaltracker.com/story/show/#{PIVOTAL_NUMBER}
MSG
STDOUT << commit_message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment