Skip to content

Commit

Permalink
Filters out duplicate offences for Github formatters
Browse files Browse the repository at this point in the history
When the same exact message is repeated on the same line,
this change removes the duplicates.  The test was updated
to reflect this changed behavior as well.
  • Loading branch information
edk committed Nov 11, 2014
1 parent 00b5199 commit 24f3019
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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 24f3019

Please sign in to comment.