Last active
December 14, 2015 21:49
-
-
Save terrafied/5154380 to your computer and use it in GitHub Desktop.
Hub pull-request command, simplified. Update defaults, then you can just run ```pull.rb``` without options for most current pull request, or easily add branch-specific info with less hassle. I'd alias to something like ```gpr```
This file contains hidden or 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' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: pull.rb [options]" | |
###### DEFAULTS | |
options[:account] = "qstream" | |
options[:base] = "trove-master" | |
options[:pull] = %x{git rev-parse --abbrev-ref HEAD}.strip | |
options[:message] = "Request to pull feature branch #{options[:pull]} into #{options[:base]}" | |
###### | |
opts.on("-a ACCOUNT", "Github account to use") do |a| | |
options[:account] = a | |
end | |
opts.on("-i ISSUE", "Tie to issue number") do |i| | |
options[:issue] = i.to_i | |
end | |
opts.on("-b BASE-REPO", "Base repository") do |b| | |
b = "trove-master" if b == "trove" | |
b = "rails31" if b == "rails" | |
options[:base] = b | |
end | |
opts.on("-p PULL-REPO", "Current (pull) repository") do |p| | |
options[:pull] = p | |
end | |
opts.on("-m MESSAGE", "Pull request message (ignored if -i switch is used)") do |m| | |
options[:message] = m | |
end | |
opts.parse! | |
end | |
cmd = "hub pull-request" | |
cmd += options[:issue].nil? ? " \"#{options[:message]}\"" : " -i #{options[:issue]}" | |
cmd += " -b #{options[:account]}:#{options[:base]}" | |
cmd += " -h #{options[:account]}:#{options[:pull]}" | |
puts %x{#{cmd}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment