Created
March 13, 2014 13:14
-
-
Save lucassus/9528236 to your computer and use it in GitHub Desktop.
Creates pull request from the current local branch
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" | |
options = Hash.new | |
parser = OptionParser.new do |opts| | |
opts.banner = "Usage: pull_request [options]" | |
opts.on("-i", "--issue=ISSUE", "GitHub issue") do |issue| | |
options[:issue] = issue | |
end | |
opts.on("-h", "--help", "Display this screen") do | |
puts parser | |
exit | |
end | |
end | |
mandatoryOptions = [:issue] | |
begin | |
parser.parse! | |
missing = mandatoryOptions.select { |param| options[param].nil? } | |
unless missing.empty? | |
puts "Missing options: #{missing.join(', ')}" | |
puts parser | |
exit | |
end | |
rescue OptionParser::InvalidOption, OptionParser::MissingArgument | |
puts $!.to_s # Friendly output when parsing fails | |
puts parser | |
exit | |
end | |
# cook the pull request | |
`git branch`.match /^\* (?<branch>.+)/ do |r| | |
`git branch --set-upstream-to=origin/#{r[:branch]}` | |
`hub pull-request -i #{options[:issue]}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment