Skip to content

Commit

Permalink
Merge pull request prontolabs#235 from ivanovaleksey/issue-233
Browse files Browse the repository at this point in the history
[Fix prontolabs#233] Skip reviewing PR without comments
  • Loading branch information
mmozuras authored May 13, 2017
2 parents 57dd837 + 61ad774 commit 8db1d43
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def create_pull_comment(comment)
end

def create_pull_request_review(comments)
return if comments.empty?

options = {
event: 'COMMENT',
accept: 'application/vnd.github.black-cat-preview+json', # https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
Expand Down
52 changes: 52 additions & 0 deletions spec/pronto/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,57 @@ module Pronto
end
end
end

describe '#create_pull_request_review' do
subject { github.create_pull_request_review(comments) }

let(:octokit_client) { double(Octokit::Client) }

before do
github.instance_variable_set(:@client, octokit_client)
end

context 'with no comments' do
let(:comments) { [] }

specify do
octokit_client.should_not_receive(:create_pull_request_review)
subject
end
end

context 'with comments' do
before do
github.should_receive(:pull_id).once.and_return(pull_id)
end

let(:pull_id) { 10 }
let(:comments) do
[
double(path: 'bad_file.rb', position: 10, body: 'Offense #1'),
double(path: 'bad_file.rb', position: 20, body: 'Offense #2')
]
end
let(:options) do
{
event: 'COMMENT',
accept: 'application/vnd.github.black-cat-preview+json',
comments: [
{ path: 'bad_file.rb', position: 10, body: 'Offense #1' },
{ path: 'bad_file.rb', position: 20, body: 'Offense #2' }
]
}
end

specify do
octokit_client
.should_not_receive(:create_pull_request_review)
.with('mmozuras/pronto', pull_id, options)
.once

subject
end
end
end
end
end

0 comments on commit 8db1d43

Please sign in to comment.