Class: Cipr::Repo
Instance Method Summary collapse
- #apply_pull_request(pr) ⇒ Object
- #auth_string ⇒ Object
- #checkout_pull_request(pr) ⇒ Object
- #comment(issue_id, body) ⇒ Object
- #git ⇒ Object
-
#initialize(repo, options = {}) ⇒ Repo
constructor
A new instance of Repo.
- #pull_request(id) ⇒ Object
- #pull_requests(state = :open) ⇒ Object
- #test ⇒ Object
Constructor Details
#initialize(repo, options = {}) ⇒ Repo
Returns a new instance of Repo.
9 10 11 12 13 14 15 |
# File 'lib/cipr/github.rb', line 9 def initialize(repo, ={}) @repo_user, @repo = repo.split("/") @directory = [:directory] @prep = [:prep] || 'bundle && rake db:migrate' @command = [:command] || 'bundle exec rake spec' @auth = {:username => [:user] || @repo_user, :password => [:password]}.reject {|k,v| v.nil?} end |
Instance Method Details
#apply_pull_request(pr) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/cipr/github.rb', line 62 def apply_pull_request(pr) pr = pull_request(pr.respond_to?(:number) ? pr.number : pr) git.reset_hard git.branch(pr.merge_to).checkout git.pull("origin", pr.merge_to) git.branch("#{pr.username}-#{pr.merge_from}").checkout git.add_remote(pr.username, pr.pull_repo) unless git.remotes.map(&:to_s).include?(pr.username) git.pull(pr.username, "#{pr.username}/#{pr.merge_from}", "Merge pull request ##{pr.number} - #{pr.title.gsub(/"/, '\"')}") end |
#auth_string ⇒ Object
78 79 80 |
# File 'lib/cipr/github.rb', line 78 def auth_string [@auth[:username], @auth[:password]].compact.join(":") end |
#checkout_pull_request(pr) ⇒ Object
72 73 74 75 76 |
# File 'lib/cipr/github.rb', line 72 def checkout_pull_request(pr) pr = pull_request(pr.respond_to?(:number) ? pr.number : pr) git.add_remote(pr.username, pr.pull_repo) unless git.remotes.map(&:to_s).include?(pr.username) git.branch("#{pr.username}/#{pr.merge_from}").checkout end |
#comment(issue_id, body) ⇒ Object
25 26 27 |
# File 'lib/cipr/github.rb', line 25 def comment(issue_id, body) post("/repos/#@repo_user/#@repo/issues/#{issue_id}/comments", :body => {'body' => body}.to_json) end |
#git ⇒ Object
58 59 60 |
# File 'lib/cipr/github.rb', line 58 def git @g ||= @directory ? Git.open(@directory) : Git.clone("https://github.com/#@repo_user/#@repo.git", @repo) end |
#pull_request(id) ⇒ Object
21 22 23 |
# File 'lib/cipr/github.rb', line 21 def pull_request(id) PullRequest.new(self, get("/repos/#@repo_user/#@repo/pulls/#{id}")) end |
#pull_requests(state = :open) ⇒ Object
17 18 19 |
# File 'lib/cipr/github.rb', line 17 def pull_requests(state=:open) get("/repos/#@repo_user/#@repo/pulls", :query => {:state => state}).map {|p| PullRequest.new(self, p)} end |
#test ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cipr/github.rb', line 29 def test tested = 0 pull_requests.each do |pr| pr = pull_request(pr.number) next if pr.merged? ready = false if pr.mergeable? puts "Applying Pull Request ##{pr.number}" ready = (pr.apply =~ /(Already|CONFLICT)/).nil? else puts "Checking out Pull Request ##{pr.number}" pr.checkout ready = true end if ready puts "Testing Pull Request ##{pr.number}" output = execute unless output.nil? || output.strip.empty? pr.comment(output) tested += 1 end end end puts "Tested #{tested} pull requests this round..." tested end |