Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
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
14 changes: 3 additions & 11 deletions lib/cc/presenters/github_pull_requests_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ def initialize(payload, repo_config)
end

def success_message
if @repo_config.pr_status_quality_stats?
if both_issue_counts_zero?
"Code Climate didn't find any new or fixed issues."
else
"Code Climate found #{formatted_issue_counts}."
end
if both_issue_counts_zero?
"Code Climate didn't find any new or fixed issues."
else
"Code Climate has analyzed this pull request."
"Code Climate found #{formatted_issue_counts}."
end
end

Expand Down Expand Up @@ -53,10 +49,6 @@ def formatted_issue_counts
def issue_counts
[@new_count, @fixed_count]
end

def issue_counts_in_payload?
issue_counts.all?
end
end
end
end
18 changes: 9 additions & 9 deletions test/github_pull_requests_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ def test_pull_request_status_pending
def test_pull_request_status_success_detailed
expect_status_update("pbrisbin/foo", "abc123", {
"state" => "success",
"description" => "Code Climate found 1 new issue and 2 fixed issues.",
"description" => "Code Climate found 2 new issues and 1 fixed issue.",
})

receive_pull_request(
{ update_status: true },
{
github_slug: "pbrisbin/foo",
commit_sha: "abc123",
state: "success",
issue_comparison_counts: {
"fixed" => 2,
"new" => 1,
}
state: "success"
},
true
)
Expand All @@ -38,7 +34,7 @@ def test_pull_request_status_success_detailed
def test_pull_request_status_success_generic
expect_status_update("pbrisbin/foo", "abc123", {
"state" => "success",
"description" => /has analyzed/,
"description" => /found 2 new issues and 1 fixed issue/,
})

receive_pull_request({ update_status: true }, {
Expand Down Expand Up @@ -179,6 +175,10 @@ def test_pull_request_comment
number: 1,
state: "success",
compare_url: "http://example.com",
issue_comparison_counts: {
"fixed" => 2,
"new" => 1,
}
})
end

Expand Down Expand Up @@ -248,7 +248,7 @@ def receive_pull_request(config, event_data, truthy_repo_config = false)
receive(
CC::Service::GitHubPullRequests,
{ oauth_token: "123" }.merge(config),
{ name: "pull_request" }.merge(event_data),
{ name: "pull_request", issue_comparison_counts: {'fixed' => 1, 'new' => 2} }.merge(event_data),
truthy_repo_config ? TruthyRepoConfig.new : FalsyRepoConfig.new
)
end
Expand All @@ -257,7 +257,7 @@ def receive_test(config, event_data = {})
receive(
CC::Service::GitHubPullRequests,
{ oauth_token: "123" }.merge(config),
{ name: "test" }.merge(event_data)
{ name: "test", issue_comparison_counts: {'fixed' => 1, 'new' => 2} }.merge(event_data)
)
end
end
21 changes: 7 additions & 14 deletions test/presenters/github_pull_requests_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,38 @@
require "cc/presenters/github_pull_requests_presenter"

class TestGitHubPullRequestsPresenter < CC::Service::TestCase
def test_message_quality_stats_not_enabled
assert_equal(
"Code Climate has analyzed this pull request.",
build_presenter(false, "fixed" => 1, "new" => 1).success_message
)
end

def test_message_singular
assert_equal(
"Code Climate found 1 new issue and 1 fixed issue.",
build_presenter(true, "fixed" => 1, "new" => 1).success_message
build_presenter("fixed" => 1, "new" => 1).success_message
)
end

def test_message_plural
assert_equal(
"Code Climate found 2 new issues and 1 fixed issue.",
build_presenter(true, "fixed" => 1, "new" => 2).success_message
build_presenter("fixed" => 1, "new" => 2).success_message
)
end

def test_message_only_fixed
assert_equal(
"Code Climate found 1 fixed issue.",
build_presenter(true, "fixed" => 1, "new" => 0).success_message
build_presenter("fixed" => 1, "new" => 0).success_message
)
end

def test_message_only_new
assert_equal(
"Code Climate found 3 new issues.",
build_presenter(true, "fixed" => 0, "new" => 3).success_message
build_presenter("fixed" => 0, "new" => 3).success_message
)
end

def test_message_no_new_or_fixed
assert_equal(
"Code Climate didn't find any new or fixed issues.",
build_presenter(true, "fixed" => 0, "new" => 0).success_message
build_presenter("fixed" => 0, "new" => 0).success_message
)
end

Expand All @@ -50,10 +43,10 @@ def build_payload(issue_counts)
{ "issue_comparison_counts" => issue_counts }
end

def build_presenter(quality_stats_enabled, issue_counts)
def build_presenter(issue_counts)
CC::Service::GitHubPullRequestsPresenter.new(
build_payload(issue_counts),
OpenStruct.new(pr_status_quality_stats?: quality_stats_enabled)
OpenStruct.new
)
end
end