Skip to content

Commit

Permalink
show existing message count when reporting posted messages
Browse files Browse the repository at this point in the history
When Developer see that there are 0 messages posted in the log, but pronto still is failed, there is no idea what's going on.

Added more insights in the message in order to prevent such confusion.
  • Loading branch information
pftg authored Apr 5, 2022
1 parent 9143cfe commit 09092b7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pronto/formatter/git_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def format(messages, repo, patches)

approve_pull_request(comments.count, additions.count, client) if defined?(self.approve_pull_request)

"#{additions.count} Pronto messages posted to #{pretty_name}"
"#{additions.count} Pronto messages posted to #{pretty_name} (#{existing.count} existing)"
end

def client_module
Expand Down
49 changes: 45 additions & 4 deletions spec/pronto/formatter/github_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module Formatter
subject { formatter.format(messages, repo, nil) }

let(:repo) { Git::Repository.new('spec/fixtures/test.git') }
let(:published_comments_msg) { "%{count} Pronto messages posted to #{formatter.pretty_name}" }
let(:published_comments_msg) do
"%<count>i Pronto messages posted to #{formatter.pretty_name} (%<existing_count>i existing)"
end

context 'with duplicates' do
context 'with duplicates in the new messages' do
let(:messages) { [message, message] }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:line) { double(new_lineno: 1, commit_sha: '123', position: nil) }
Expand All @@ -25,7 +27,46 @@ module Formatter
.should_receive(:create_commit_comment)
.once

subject.should eq format(published_comments_msg, count: 1)
subject.should eq format(published_comments_msg, count: 1, existing_count: 0)
end
end

context 'with duplicates in the existed messages' do
let(:messages) { [message] }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
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([double(body: 'crucial', path: 'path/to', position: nil)])

Octokit::Client.any_instance.should_not_receive(:create_commit_comment)

subject.should eq format(published_comments_msg, count: 0, existing_count: 1)
end
end

context 'with one duplicate and one non duplicated messages' do
let(:messages) { [message, existed_message] }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:existed_message) { Message.new('path/to', line, :warning, 'existed') }
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([double(body: 'existed', path: 'path/to', position: nil)])

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

subject.should eq format(published_comments_msg, count: 1, existing_count: 1)
end
end

Expand All @@ -51,7 +92,7 @@ module Formatter
.should_receive(:create_commit_comment)
.twice

subject.should eq format(published_comments_msg, count: 2)
subject.should eq format(published_comments_msg, count: 2, existing_count: 0)
end
end
end
Expand Down

0 comments on commit 09092b7

Please sign in to comment.