Last active
August 29, 2015 14:03
-
-
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.
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 | |
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