Last active
January 15, 2019 04:47
-
-
Save pxlpnk/71919037fd477b9d2ca4a25c2c678455 to your computer and use it in GitHub Desktop.
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 'optparse' | |
class CommitParser | |
def self.parse(args) | |
options = {} | |
opts = OptionParser.new do |opts| | |
opts.banner = 'Usage: name' | |
opts.on('-p ', '--pairee PAIREE', 'Who do you pair with? single user or pipe separated list "name1|name2"') do |pairee| | |
options[:pairee] = pairee | |
end | |
opts.on('-t', '--ticket TICKET', 'Ticket id') do |ticket| | |
options[:ticket] = ticket | |
end | |
opts.on('-m', '--message MESSAGE', 'Commit Message') do |message| | |
options[:message] = message | |
end | |
opts.on("-h", "--help", "Prints this help") do | |
puts opts | |
exit | |
end | |
end | |
begin | |
opts.parse(args) | |
rescue StandardError => e | |
puts "Exception encountered: #{e}" | |
exit 1 | |
end | |
options | |
end | |
end | |
options = CommitParser.parse(ARGV) | |
# defaults | |
my_name = 'Andy' | |
commit_message = '' | |
if options[:message] | |
commit_message = options[:message] | |
else | |
puts "Required commit message is not given -m \"My Commit Message\"" | |
exit 1 | |
end | |
message = [] | |
message << "[#{options[:ticket]}]" if options[:ticket] | |
message << if options[:pairee] | |
"[#{my_name}|#{options[:pairee]}]" | |
else | |
"[#{my_name}]" | |
end | |
message << " " | |
message << commit_message | |
message = message.join('') | |
command = "git commit -m '#{message}'" | |
puts command | |
puts `#{command}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment