Skip to content

Commit

Permalink
team id instead of whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmullins committed Sep 13, 2016
1 parent d8beb60 commit ae01f23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
24 changes: 11 additions & 13 deletions lib/lita/github_pr_list/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
module Lita
module GithubPrList
class PullRequest
attr_accessor :github_client, :github_organization, :github_pull_requests, :response, :repo_whitelist
attr_accessor :github_client, :github_organization, :github_pull_requests, :response, :team_id

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.repo_whitelist = params.fetch(:repo_whitelist, nil)
self.team_id =params.fetch(:team_id, nil)
self.github_pull_requests = []

raise "invalid params in #{self.class.name}" if response.nil? || github_token.nil? || github_organization.nil?
raise "invalid params in #{self.class.name}" if response.nil? || github_token.nil? || github_organization.nil? || team_id.nil?

self.github_client = Octokit::Client.new(access_token: github_token, auto_paginate: true)
end
Expand All @@ -25,26 +25,24 @@ def list
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|
if i.pull_request && repo_whitelist.find_index(i.repository.name)
# puts "John: #{i.repository.name}"
github_pull_requests << i
puts "Gathering PRs..."
github_client.team_repositories(team_id).each do |repo|
github_client.list_issues(repo.id).each do |issue|
if issue.pull_request
issue.repository = repo
github_pull_requests << issue
end
end
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} #{pr_issue.user.login} #{pr_issue.title} #{pr_issue.pull_request.html_url}"
"#{pr_issue.repository.name}\t#{pr_issue.user.login}\t#{pr_issue.title} #{pr_issue.pull_request.html_url}"
end
end

def repo_status(repo_full_name, issue)
# puts "#{repo_full_name} #{issue.body}"
issue.body = "" if issue.body.nil?
status_object = Lita::GithubPrList::Status.new(comment: ":new: " + issue.body)
status = status_object.comment_status
Expand Down
8 changes: 4 additions & 4 deletions lib/lita/handlers/github_pr_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.default_config(config)
config.comment_hook_event_type = nil
config.pull_request_open_message_hook_url = nil
config.pull_request_open_message_hook_event_type = nil
config.repo_whitelist = nil
config.team_id = nil
end

route(/pr list/i, :list_org_pr, command: true,
Expand All @@ -42,7 +42,7 @@ def self.default_config(config)
def list_org_pr(response)
pull_requests = Lita::GithubPrList::PullRequest.new({ github_organization: github_organization,
github_token: github_access_token,
repo_whitelist: repo_whitelist,
team_id: team_id,
response: response }).list
merge_requests = redis.keys("gitlab_mr*").map { |key| redis.get(key) }

Expand Down Expand Up @@ -111,8 +111,8 @@ def github_access_token
Lita.config.handlers.github_pr_list.github_access_token
end

def repo_whitelist
Lita.config.handlers.github_pr_list.repo_whitelist
def team_id
Lita.config.handlers.github_pr_list.team_id
end

def hook_info
Expand Down

0 comments on commit ae01f23

Please sign in to comment.