Created
May 27, 2009 16:41
-
-
Save ddollar/118740 to your computer and use it in GitHub Desktop.
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
| ## usage ##################################################################### | |
| # | |
| # patch-tester.rb <ticket_id> | |
| # | |
| # specify which branches to test against below (TEST_BRANCHES) | |
| # creates <ticket_id>-<branch> branches with the latest patch on the ticket | |
| # applied | |
| require 'open-uri' | |
| require 'rexml/document' | |
| require 'tempfile' | |
| require 'net/https' | |
| TICKET_FORMAT = 'http://rails.lighthouseapp.com/projects/8994/tickets/%s.xml' | |
| TEST_BRANCHES = %w( master 2-3-stable ) | |
| def ticket(id) | |
| REXML::Document.new(open(TICKET_FORMAT % id)) | |
| end | |
| def attachment(url) | |
| uri = URI.parse(url) | |
| http = Net::HTTP.new(uri.host, uri.port) | |
| http.use_ssl = true | |
| http.get(uri.path).body | |
| end | |
| def current_branch | |
| path = Dir.pwd | |
| until File.exists?(File.join(path, '.git', 'HEAD')) | |
| raise 'Can not find .git directory' if path == '/' | |
| path = File.dirname(path) | |
| end | |
| end | |
| unless ticket_id = ARGV.first | |
| puts "usage: #{File.basename(__FILE__)} <ticket_id>" | |
| exit 1 | |
| end | |
| current_branch | |
| attachment_url = ticket(ticket_id).elements['//attachment/url[last()]'].text | |
| attachment_url.gsub!(/\Ahttp/, 'https') | |
| patch_path = nil | |
| Tempfile.open('rails-patch') do |temp| | |
| patch_path = temp.path | |
| temp.puts(attachment(attachment_url)) | |
| end | |
| original_branch = current_branch | |
| TEST_BRANCHES.each do |branch| | |
| test_branch = "#{ticket_id}-#{branch}" | |
| %x( git checkout #{branch} ) | |
| %x( git checkout -b #{ticket_id}-#{branch} ) | |
| %x( git am #{patch_path} ) if current_branch == test_branch | |
| end | |
| %x( git checkout #{original_branch} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment