Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters out duplicate offences for Github formatters #44

Merged
merged 2 commits into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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