Skip to content

Commit

Permalink
Merge pull request prontolabs#44 from edk/github_formatter_filter_dup…
Browse files Browse the repository at this point in the history
…licates

Filters out duplicate offences for Github formatters
  • Loading branch information
mmozuras committed Nov 11, 2014
2 parents 00b5199 + 4ea0497 commit 603ffef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Try to detect pull request id automatically, if `PULL_REQUEST_ID` is not specified. Inspired by @willnet/prid.
* [#40](https://github.com/mmozuras/pronto/issues/40): Add '--index' option for 'pronto run'. Pronto analyzes changes before committing.

### Changes
* Github and Github pull request formatters now filter out duplicate offenses on the same line to avoid spamming with redundant comments.

## 0.3.3

### Bugs fixed
Expand Down
2 changes: 2 additions & 0 deletions lib/pronto/formatter/github_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Pronto
module Formatter
class GithubFormatter
def format(messages, repo)
messages = messages.uniq { |message| [message.msg, message.line.new_lineno] }

commit_messages = messages.map do |message|
sha = message.commit_sha
body = message.msg
Expand Down
2 changes: 2 additions & 0 deletions lib/pronto/formatter/github_pull_request_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Pronto
module Formatter
class GithubPullRequestFormatter
def format(messages, repo)
messages = messages.uniq { |message| [message.msg, message.line.new_lineno] }

commit_messages = messages.map do |message|
body = message.msg
path = message.path
Expand Down
27 changes: 27 additions & 0 deletions spec/pronto/formatter/github_formattter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ module Formatter
let(:line) { double(new_lineno: 1, commit_sha: '123', position: nil) }
before { line.stub(:commit_line).and_return(line) }

specify do
Octokit::Client.any_instance
.should_receive(:commit_comments)
.once
.and_return([])

Octokit::Client.any_instance
.should_receive(:create_commit_comment)
.once

subject
end
end

describe '#format without duplicates' do
subject { github_formatter.format(messages, repository) }
let(:messages) { [message1, message2] }
let(:repository) { Git::Repository.new('.') }
let(:message1) { Message.new('path/to1', line1, :warning, 'crucial') }
let(:message2) { Message.new('path/to2', line2, :warning, 'crucial') }
let(:line1) { double(new_lineno: 1, commit_sha: '123', position: nil) }
let(:line2) { double(new_lineno: 2, commit_sha: '123', position: nil) }
before do
line1.stub(:commit_line).and_return(line1)
line2.stub(:commit_line).and_return(line2)
end

specify do
Octokit::Client.any_instance
.should_receive(:commit_comments)
Expand Down

0 comments on commit 603ffef

Please sign in to comment.