From 7bd8df50bed124c4d17ab867ddcc9495d4d77620 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Thu, 28 Feb 2013 10:48:06 -0800 Subject: [PATCH] add task to get all testable pull requests This commmit adds a rake task that can be used to get a list of all testable pull requests. it also adds a more general purpose lib that supports this functionality. --- Rakefile | 13 +++++++++++ lib/puppetlabs/os_tester/github.rb | 35 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/Rakefile b/Rakefile index 5fdb38f..57ac1ce 100644 --- a/Rakefile +++ b/Rakefile @@ -34,6 +34,17 @@ end namespace :openstack do + desc 'get testable pull requests' + task :testable_pull_requests do + testable_pull_requests( + ['cinder', 'nova', 'glance', 'openstack', 'keystone', 'horizon'], + github_admins, + github_login, + github_password, + 'ready_for_testing' + ) + end + desc 'clone all required modules' task :setup do cmd_system('librarian-puppet install') @@ -169,6 +180,7 @@ namespace :test do test_pull_request( args.repo_name, args.pull_request_number, + github_admins, github_login, github_password, 'spec/test_swift_cluster.rb', @@ -182,6 +194,7 @@ namespace :test do test_pull_request( args.repo_name, args.pull_request_number, + github_admins, github_login, github_password, 'spec/test_two_node.rb', diff --git a/lib/puppetlabs/os_tester/github.rb b/lib/puppetlabs/os_tester/github.rb index 45b1109..b5e4843 100644 --- a/lib/puppetlabs/os_tester/github.rb +++ b/lib/puppetlabs/os_tester/github.rb @@ -209,6 +209,41 @@ module Puppetlabs 'body' => "Test #{outcome}. Results can be found here: #{gist_response.html_url}" ) end + + def testable_pull_requests( + project_names, + admin_users, + github_login, + github_password, + test_message = 'schedule_for_testing' + ) + testable_pull_requests = {} + each_repo do |repo_name| + if project_names.include?(repo_name) + options = { :login => github_login, :password => github_password } + prs = ::Github.new(options).pull_requests.list('puppetlabs', "puppetlabs-#{repo_name}") + prs.each do |pr| + # the data structure of pr returned from list (above) appears to be in a different format + # than this get call, therefor, I need to get the number, and make this extra call. + # this seems to justify my experience so far that this github_api plugin may not be worth using. + number = pr['number'] + pr = ::Github.new(options).pull_requests.get('puppetlabs', "puppetlabs-#{repo_name}", number) + # I know this is lazy to do b/c it means every pull request will be validated twice based + # on the current workflow with jenkins (where this will populate parameterized builds + # that also check if the pull request is valid + if testable_pull_request?(pr, admin_users + github_login.to_a, test_message, options) + if testable_pull_requests[repo_name] + testable_pull_requests[repo_name].push(number) + else + testable_pull_requests[repo_name] = [number] + end + end + end + end + end + puts testable_pull_requests.inspect + end + end # end Github end