-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpull_request.rb
61 lines (50 loc) · 2.03 KB
/
pull_request.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
57
58
59
60
61
require "octokit"
module Lita
module GithubPrList
class PullRequest
attr_accessor :github_client, :github_organization, :github_pull_requests, :response
def initialize(params = {})
self.response = params.fetch(:response, nil)
github_token = params.fetch(:github_token, nil)
self.github_organization = params.fetch(:github_organization, nil)
self.github_pull_requests = []
raise "invalid params in #{self.class.name}" if response.nil? || github_token.nil? || github_organization.nil?
self.github_client = Octokit::Client.new(access_token: github_token, auto_paginate: true)
end
def list
get_pull_requests
build_summary
end
private
def get_pull_requests
# Grab the issues and sort out the pull request issues by repos name
issues = github_client.org_issues(github_organization, filter: 'all')
issues.sort! { |a,b| a.repository.name.downcase <=> b.repository.name.downcase }
issues.each do |i|
github_pull_requests << i if i.pull_request
end
end
def build_summary
github_pull_requests.map do |pr_issue|
status = repo_status("#{pr_issue.repository.full_name}", pr_issue)
"#{pr_issue.repository.name} #{status} #{pr_issue.title} #{pr_issue.pull_request.html_url} (#{pr_opener pr_issue})"
end
end
def repo_status(repo_full_name, issue)
status_object = Lita::GithubPrList::Status.new(comment: ":new: " + issue.body)
status = status_object.comment_status
comments(repo_full_name, issue.number).each do |c|
status = status_object.update(c.body)
end
status[:list]
end
def comments(repo_full_name, issue_number, options = nil)
github_options = options || { direction: 'asc', sort: 'created' }
github_client.issue_comments(repo_full_name, issue_number, github_options)
end
def pr_opener(pr)
pr.user.nil? ? 'unknown' : pr.user.login
end
end
end
end