Skip to content

Commit

Permalink
Adds option to filter already-reviewed pull requests, regardless of a…
Browse files Browse the repository at this point in the history
…pproval status
  • Loading branch information
rgeraldporter committed Feb 7, 2018
1 parent 2ef2e4b commit cec6656
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export SLACK_WEBHOOK="get_your_incoming_webhook_link_for_your_slack_group_channe
export SLACK_CHANNEL="#whatever-channel-you-prefer"
export GITHUB_MEMBERS="netflash,binaryberry,otheruser"
export GITHUB_USE_LABELS=true
export GITHUB_EXCLUDE_REVIEWED=true
export GITHUB_EXCLUDE_LABELS="[DO NOT MERGE],Don't merge,DO NOT MERGE,Waiting on factcheck,wip"
export GITHUB_EXCLUDE_REPOS="notmyproject,someotherproject" # Ensure these projects are *NOT* included
export GITHUB_INCLUDE_REPOS="definitelymyproject,forsuremyproject" # Ensure *only* these projects will be included
Expand Down Expand Up @@ -106,6 +107,7 @@ docker run -it --rm --name seal \
-e DYNO=${DYNO} \
-e SLACK_CHANNEL=${SLACK_CHANNEL} \
-e GITHUB_MEMBERS=${GITHUB_MEMBERS} \
-e GITHUB_EXCLUDE_REVIEWED=${GITHUB_EXCLUDE_REVIEWED} \
-e GITHUB_USE_LABELS=${GITHUB_USE_LABELS} \
-e "GITHUB_EXCLUDE_LABELS=${GITHUB_EXCLUDE_LABELS}" \
-e "SEAL_QUOTES=${SEAL_QUOTES}" \
Expand Down Expand Up @@ -220,6 +222,9 @@ docker run -it --rm --name seal \
6th of January
- Seal can now post random quotes from the team's list of quotes in the config. Can be used as a reminder or for inspirational quotes!

7th of February
- Seal can exclude pull requests that have been already reviewed by at least one peer, regardless of approval status

## Tips

How to list your organisation's repositories modified within the last year:
Expand Down
14 changes: 11 additions & 3 deletions lib/github_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class GithubFetcher

attr_accessor :people

def initialize(team_members_accounts, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos)
def initialize(team_members_accounts, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos, exclude_reviewed)
@github = Octokit::Client.new(:access_token => ENV['GITHUB_TOKEN'])
@github.user.login
@github.auto_paginate = true
Expand All @@ -18,6 +18,7 @@ def initialize(team_members_accounts, use_labels, exclude_labels, exclude_titles
@labels = {}
@exclude_repos = exclude_repos
@include_repos = include_repos
@exclude_reviewed = exclude_reviewed
end

def list_pull_requests
Expand All @@ -30,7 +31,7 @@ def list_pull_requests

private

attr_reader :use_labels, :exclude_labels, :exclude_titles, :exclude_repos, :include_repos
attr_reader :use_labels, :exclude_labels, :exclude_titles, :exclude_repos, :include_repos, :exclude_reviewed

def present_pull_request(pull_request, repo_name)
pr = {}
Expand Down Expand Up @@ -83,7 +84,8 @@ def hidden?(pull_request, repo)
excluded_label?(pull_request, repo) ||
excluded_title?(pull_request.title) ||
!person_subscribed?(pull_request) ||
(include_repos && !explicitly_included_repo?(repo))
(include_repos && !explicitly_included_repo?(repo)) ||
excluded_reviewed?(pull_request, repo)
end

def excluded_label?(pull_request, repo)
Expand All @@ -101,6 +103,12 @@ def excluded_repo?(repo)
exclude_repos.include?(repo)
end

def excluded_reviewed?(pull_request, repo)
return false unless exclude_reviewed
reviews = @github.get("repos/#{ORGANISATION}/#{repo}/pulls/#{pull_request.number}/reviews")
reviews.any?
end

def explicitly_included_repo?(repo)
return false unless include_repos
include_repos.include?(repo)
Expand Down
9 changes: 6 additions & 3 deletions lib/seal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def team_params(team)
exclude_titles = config['exclude_titles']
exclude_repos = config['exclude_repos']
include_repos = config['include_repos']
exclude_reviewed = config['exclude_reviewed']
@quotes = config['quotes']
else
members = ENV['GITHUB_MEMBERS'] ? ENV['GITHUB_MEMBERS'].split(',') : []
Expand All @@ -65,20 +66,22 @@ def team_params(team)
exclude_titles = ENV['GITHUB_EXCLUDE_TITLES'] ? ENV['GITHUB_EXCLUDE_TITLES'].split(',') : nil
exclude_repos = ENV['GITHUB_EXCLUDE_REPOS'] ? ENV['GITHUB_EXCLUDE_REPOS'].split(',') : nil
include_repos = ENV['GITHUB_INCLUDE_REPOS'] ? ENV['GITHUB_INCLUDE_REPOS'].split(',') : nil
exclude_reviewed = ENV['GITHUB_EXCLUDE_REVIEWED'] ? true : false
@quotes = ENV['SEAL_QUOTES'] ? ENV['SEAL_QUOTES'].split(',') : nil
end
return fetch_from_github(members, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos) if @mode == nil
return fetch_from_github(members, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos, exclude_reviewed) if @mode == nil
@quotes
end


def fetch_from_github(members, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos)
def fetch_from_github(members, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos, exclude_reviewed)
git = GithubFetcher.new(members,
use_labels,
exclude_labels,
exclude_titles,
exclude_repos,
include_repos
include_repos,
exclude_reviewed
)
git.list_pull_requests
end
Expand Down
4 changes: 3 additions & 1 deletion spec/github_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
exclude_labels,
exclude_titles,
exclude_repos,
include_repos
include_repos,
exclude_reviewed
)
end

Expand Down Expand Up @@ -63,6 +64,7 @@
let(:exclude_titles) { nil }
let(:exclude_repos) { nil }
let(:include_repos) { nil }
let(:exclude_reviewed) { nil }
let(:team_members_accounts) { %w(binaryberry boffbowsh jackscotti tekin elliotcm tommyp mattbostock) }
let(:pull_2266) do
double(Sawyer::Resource,
Expand Down
8 changes: 5 additions & 3 deletions spec/seal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'exclude_titles' => nil,
'exclude_repos' => nil,
'include_repos' => nil,
'exclude_reviewed' => nil,
},
'tigers' => {
'members' => [],
Expand All @@ -20,6 +21,7 @@
'exclude_titles' => nil,
'exclude_repos' => nil,
'include_repos' => nil,
'exclude_reviewed' => nil,
}
}
end
Expand All @@ -46,7 +48,7 @@
it 'fetches PRs for the tigers and only the tigers' do
expect(GithubFetcher)
.to receive(:new)
.with([], nil, nil, nil, nil, nil)
.with([], nil, nil, nil, nil, nil, nil)
.and_return(instance_double(GithubFetcher, list_pull_requests: []))

seal.bark
Expand All @@ -62,12 +64,12 @@
it 'fetches PRs for the lions and the tigers' do
expect(GithubFetcher)
.to receive(:new)
.with([], nil, nil, nil, nil, nil)
.with([], nil, nil, nil, nil, nil, nil)
.and_return(instance_double(GithubFetcher, list_pull_requests: []))

expect(GithubFetcher)
.to receive(:new)
.with([], nil, nil, nil, nil, nil)
.with([], nil, nil, nil, nil, nil, nil)
.and_return(instance_double(GithubFetcher, list_pull_requests: []))

seal.bark
Expand Down

0 comments on commit cec6656

Please sign in to comment.