Skip to content

Instantly share code, notes, and snippets.

@lucassus
Created March 13, 2014 13:14
Show Gist options
  • Save lucassus/9528236 to your computer and use it in GitHub Desktop.
Save lucassus/9528236 to your computer and use it in GitHub Desktop.
Creates pull request from the current local branch
#!/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