Skip to content

Instantly share code, notes, and snippets.

@thexavismith
Created August 11, 2015 22:55
Show Gist options
  • Save thexavismith/f6574241aa4cca19ba27 to your computer and use it in GitHub Desktop.
Save thexavismith/f6574241aa4cca19ba27 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
message_file = ARGV[0]
original_message = File.read(message_file)
current_branch = `git rev-parse --abbrev-ref HEAD`
story_number_regex = /[a-zA-Z]+-[0-9]+/
regex_match = current_branch.match(story_number_regex)
message_match = original_message.match(story_number_regex)
message = if regex_match
if message_match
original_message
else
story_number = regex_match[0].upcase
"#{story_number} #{original_message}"
end
else
original_message
end
File.open(message_file, 'w') { |f| f.write message }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment