Created
May 10, 2012 17:51
-
-
Save jeremyf/2654728 to your computer and use it in GitHub Desktop.
A command line tool to help with testing pull requests.
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 | |
# Before you use this: | |
# git clone git://github.com/some-other-user/their-repo | |
# This assumes that origin is the repo that you are merging into! | |
require 'rubygems' | |
gem 'rest-client' | |
gem 'crack' | |
require 'rest-client' | |
require 'crack' | |
CURRENT_PATH = ENV['PWD'].freeze | |
pull_request_number = ARGV[0].freeze | |
puts "Did not specify pull_request_number" and exit(-1) unless pull_request_number | |
def execute_commands(*args) | |
commands = [%(cd #{CURRENT_PATH})] | |
commands += args | |
system(commands.join(';')) | |
end | |
remote_origin_url = `cd #{CURRENT_PATH}; git config remote.origin.url`.strip | |
api_remote_repo_url = api_remote_repo_url = remote_origin_url.sub(/(git|https?):\/\//,'https://api.').sub(/\.git$/,'').sub("github.com/",'github.com/repos/') | |
api_pull_request_url = "#{api_remote_repo_url}/pulls/#{pull_request_number}" | |
puts api_pull_request_url | |
response = RestClient.get(api_pull_request_url, :accept => :json) | |
pull_request = Crack::JSON.parse(response.body) | |
if pull_request['merged'] | |
puts "Pull request number(#{pull_request_number}) already merged" | |
else | |
execute_commands( | |
"git checkout --track -B #{pull_request['base']['ref']} origin/#{pull_request['base']['ref']}", | |
"git pull --rebase" | |
) | |
return unless execute_commands(%(git checkout -B #{pull_request_number})) | |
if execute_commands( | |
%(git remote add #{pull_request_number}-source #{pull_request['head']['repo']['git_url']}), | |
%(git pull #{pull_request_number}-source #{pull_request['head']['ref']}) | |
) | |
execute_commands("bundle exec rake") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment