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)