diff --git a/lib/lita/github_pr_list/pull_request.rb b/lib/lita/github_pr_list/pull_request.rb index 26cfce1..b731aa1 100644 --- a/lib/lita/github_pr_list/pull_request.rb +++ b/lib/lita/github_pr_list/pull_request.rb @@ -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 @@ -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 diff --git a/lib/lita/handlers/github_pr_list.rb b/lib/lita/handlers/github_pr_list.rb index 22f0a07..91009c6 100644 --- a/lib/lita/handlers/github_pr_list.rb +++ b/lib/lita/handlers/github_pr_list.rb @@ -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, @@ -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) } @@ -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