Skip to content

Commit

Permalink
Add configurable Github review_type with 'REQUEST_CHANGES' as default (
Browse files Browse the repository at this point in the history
…prontolabs#334)

* Add configurable github review_type with 'request_changes' as default

* Use 'COMMENT' as default instead of 'REQUEST_CHANGES'
  • Loading branch information
gyfis authored and doomspork committed Sep 19, 2019
1 parent 0270754 commit 351eb04
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/pronto/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def consolidate_comments?
consolidated
end

def github_review_type
review_type =
ENV['PRONTO_GITHUB_REVIEW_TYPE'] ||
@config_hash.fetch('github_review_type', false)

if review_type == 'request_changes'
'REQUEST_CHANGES'
else
'COMMENT'
end
end

def excluded_files(runner)
files =
if runner == 'all'
Expand Down
3 changes: 2 additions & 1 deletion lib/pronto/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ConfigFile
'slug' => nil,
'access_token' => nil,
'api_endpoint' => 'https://api.github.com/',
'web_endpoint' => 'https://github.com/'
'web_endpoint' => 'https://github.com/',
'review_type' => 'request_changes'
},
'gitlab' => {
'slug' => nil,
Expand Down
4 changes: 2 additions & 2 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def create_commit_status(status)

def create_pull_request_review(comments)
options = {
event: 'COMMENT',
event: @config.github_review_type,
accept: 'application/vnd.github.v3.diff+json', # https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
comments: comments.map do |comment|
{
{
path: comment.path,
position: comment.position,
body: comment.body
Expand Down
3 changes: 2 additions & 1 deletion spec/pronto/config_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module Pronto
'slug' => nil,
'access_token' => nil,
'api_endpoint' => 'https://api.github.com/',
'web_endpoint' => 'https://github.com/'
'web_endpoint' => 'https://github.com/',
'review_type' => 'request_changes'
}
)
end
Expand Down
19 changes: 19 additions & 0 deletions spec/pronto/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ module Pronto
it { should == 'github.com' }
end

describe '#github_review_type' do
subject { config.github_review_type }

context 'from env variable' do
before { stub_const('ENV', 'PRONTO_GITHUB_REVIEW_TYPE' => 'request_changes') }
it { should == 'REQUEST_CHANGES' }
end

context 'from config hash' do
let(:config_hash) { { 'github' => { 'review_type' => 'something_else' } } }
it { should == 'COMMENT' }
end

context 'default' do
let(:config_hash) { ConfigFile::EMPTY }
it { should == 'COMMENT' }
end
end

describe '#gitlab_slug' do
subject { config.gitlab_slug }

Expand Down

0 comments on commit 351eb04

Please sign in to comment.