Skip to content

Commit

Permalink
whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmullins committed Sep 13, 2016
1 parent 37a2d81 commit 52e520c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ tmp
*.a
mkmf.log
vendor
.env
.env
.idea/
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lita-github_pr_list
# lita-github_pr_list (whitelist)

`lita-github_pr_list` is a handler for Lita that connects up with GitHub and lists an organization's pull requests
`lita-github_pr_list` is a handler for Lita that connects up with GitHub and lists an organization's pull requests from a list of repos.

## Installation

Expand All @@ -23,6 +23,7 @@ Lita.configure do |config|
...
config.handlers.github_pr_list.github_organization = ENV['GITHUB_ORG']
config.handlers.github_pr_list.github_access_token = ENV['GITHUB_TOKEN']
config.handlers.github_pr_list.repo_whitelist = %w(repo1 repo2 repo3)
...
end
```
Expand All @@ -31,7 +32,7 @@ end

```Lita: pr list```

All of the open pull requests for an organization will get listed out from lita. If it has one of the emoji statuses below it
All of the open pull requests in the whitelist for an organization will get listed out from lita. If it has one of the emoji statuses below it
will display it, otherwise it will display :new:.

## Emoji status
Expand Down
10 changes: 8 additions & 2 deletions lib/lita/github_pr_list/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
module Lita
module GithubPrList
class PullRequest
attr_accessor :github_client, :github_organization, :github_pull_requests, :response
attr_accessor :github_client, :github_organization, :github_pull_requests, :response, :repo_whitelist

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.github_pull_requests = []

raise "invalid params in #{self.class.name}" if response.nil? || github_token.nil? || github_organization.nil?
Expand All @@ -28,7 +29,10 @@ def get_pull_requests
issues.sort! { |a,b| a.repository.name.downcase <=> b.repository.name.downcase }

issues.each do |i|
github_pull_requests << i if i.pull_request
if i.pull_request && repo_whitelist.find_index(i.repository.name)
# puts "John: #{i.repository.name}"
github_pull_requests << i
end
end
end

Expand All @@ -40,6 +44,8 @@ def build_summary
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
comments(repo_full_name, issue.number).each do |c|
Expand Down
6 changes: 6 additions & 0 deletions lib/lita/handlers/github_pr_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +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
end

route(/pr list/i, :list_org_pr, command: true,
Expand All @@ -41,6 +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,
response: response }).list
merge_requests = redis.keys("gitlab_mr*").map { |key| redis.get(key) }

Expand Down Expand Up @@ -109,6 +111,10 @@ 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
end

def hook_info
{ comment_hook: { hook_url: comment_hook_url, event_type: comment_hook_event_type },
pull_request_open_message_hook: { hook_url: pull_request_open_message_hook_url, event_type: pull_request_open_message_hook_event_type } }
Expand Down

0 comments on commit 52e520c

Please sign in to comment.