Created
October 19, 2012 13:34
-
-
Save jferris/3918253 to your computer and use it in GitHub Desktop.
Check out pull requests from the command line
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 '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