diff --git a/README.md b/README.md index 920e2b4c..ab21b677 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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}" \ @@ -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: diff --git a/lib/github_fetcher.rb b/lib/github_fetcher.rb index bc58d409..b3b99c71 100644 --- a/lib/github_fetcher.rb +++ b/lib/github_fetcher.rb @@ -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 @@ -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 @@ -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 = {} @@ -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) @@ -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) diff --git a/lib/seal.rb b/lib/seal.rb index b5ae7b9f..99d1402f 100755 --- a/lib/seal.rb +++ b/lib/seal.rb @@ -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(',') : [] @@ -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 diff --git a/spec/github_fetcher_spec.rb b/spec/github_fetcher_spec.rb index 1c0dc5cf..f5f547a4 100644 --- a/spec/github_fetcher_spec.rb +++ b/spec/github_fetcher_spec.rb @@ -8,7 +8,8 @@ exclude_labels, exclude_titles, exclude_repos, - include_repos + include_repos, + exclude_reviewed ) end @@ -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, diff --git a/spec/seal_spec.rb b/spec/seal_spec.rb index e4aee517..47eca4e0 100644 --- a/spec/seal_spec.rb +++ b/spec/seal_spec.rb @@ -12,6 +12,7 @@ 'exclude_titles' => nil, 'exclude_repos' => nil, 'include_repos' => nil, + 'exclude_reviewed' => nil, }, 'tigers' => { 'members' => [], @@ -20,6 +21,7 @@ 'exclude_titles' => nil, 'exclude_repos' => nil, 'include_repos' => nil, + 'exclude_reviewed' => nil, } } end @@ -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 @@ -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