Skip to content

Instantly share code, notes, and snippets.

@midwire
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midwire/7e325bc23ad4a3ca544d to your computer and use it in GitHub Desktop.
Save midwire/7e325bc23ad4a3ca544d to your computer and use it in GitHub Desktop.
Create a commit message, with link to a Pivotal story, based on the branch name and put it all on the clipboard.
#!/usr/bin/env ruby
require 'pry-nav'
def pbcopy(input)
str = input.to_s
IO.popen('pbcopy', 'w') { |f| f << str }
str
end
branch_name = `git rev-parse --abbrev-ref HEAD`.chomp
DIVIDERS = %r{[-|_|/|\/]}
parts = branch_name.match(/(?<initials>.+)#{DIVIDERS}(?<number>\d{5,})#{DIVIDERS}(?<description>.*)/)
if parts.nil?
# Initials missing?
parts = branch_name.match(/(?<number>\d{5,})#{DIVIDERS}(?<description>.*)/)
INITIALS = 'CB'
end
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
pbcopy(commit_message)
puts(">>> Commit message is on the clipboard!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment