From 24f3019183dd500a7477be473899f3fbbc053798 Mon Sep 17 00:00:00 2001 From: Eddy Kim Date: Tue, 11 Nov 2014 07:54:08 -0800 Subject: [PATCH] Filters out duplicate offences for Github formatters 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. --- lib/pronto/formatter/github_formatter.rb | 2 ++ .../github_pull_request_formatter.rb | 2 ++ .../formatter/github_formattter_spec.rb | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/lib/pronto/formatter/github_formatter.rb b/lib/pronto/formatter/github_formatter.rb index e0de75d4..9c0092e2 100644 --- a/lib/pronto/formatter/github_formatter.rb +++ b/lib/pronto/formatter/github_formatter.rb @@ -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 diff --git a/lib/pronto/formatter/github_pull_request_formatter.rb b/lib/pronto/formatter/github_pull_request_formatter.rb index a07f0fdb..db9223c3 100644 --- a/lib/pronto/formatter/github_pull_request_formatter.rb +++ b/lib/pronto/formatter/github_pull_request_formatter.rb @@ -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 diff --git a/spec/pronto/formatter/github_formattter_spec.rb b/spec/pronto/formatter/github_formattter_spec.rb index b6515541..e6132372 100644 --- a/spec/pronto/formatter/github_formattter_spec.rb +++ b/spec/pronto/formatter/github_formattter_spec.rb @@ -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)