Skip to content

Instantly share code, notes, and snippets.

@jferris
Created October 19, 2012 13:34
Show Gist options
  • Select an option

  • Save jferris/3918253 to your computer and use it in GitHub Desktop.

Select an option

Save jferris/3918253 to your computer and use it in GitHub Desktop.
Check out pull requests from the command line
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/https'
require 'fileutils'
def usage
puts "usage: copr project_name id"
puts "example: copr capybara-webkit 316"
exit(1)
end
id = ARGV[0] || usage
project = File.basename(FileUtils.pwd)
http = Net::HTTP.new('api.github.com', 443)
http.use_ssl = true
url = "/repos/thoughtbot/#{project}/pulls/#{id}"
response = http.get(url)
data = JSON.parse(response.body)
git_url = data["head"]["repo"]["git_url"]
user = data["head"]["repo"]["owner"]["login"]
source_branch = data["head"]["ref"]
target_branch = source_branch == "master" ? user : source_branch
unless `git remote`.include?(user)
`git remote add #{user} #{git_url}`
end
`git fetch #{user}`
`git checkout -b #{target_branch} #{user}/#{source_branch}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment