Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 4dc720f

Browse files
author
Ian C. Anderson
committed
PR service: nested hash structure for issue counts
https://trello.com/c/f17uUGRd
1 parent 910193f commit 4dc720f

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

lib/cc/services/github_pull_requests_presenter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
class CC::Service::GitHubPullRequests::Presenter
22
def initialize(payload)
3-
@fixed_count = payload["fixed_issue_count"]
4-
@new_count = payload["new_issue_count"]
3+
issue_comparison_counts = payload["issue_comparison_counts"]
4+
5+
if issue_comparison_counts
6+
@fixed_count = issue_comparison_counts["fixed"]
7+
@new_count = issue_comparison_counts["new"]
8+
end
59
end
610

711
def success_message

test/github_pull_requests_presenter_test.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,49 @@ class TestGitHubPullRequestsPresenter < CC::Service::TestCase
44
def test_message_no_issue_counts_in_payload
55
assert_equal(
66
"Code Climate has analyzed this pull request.",
7-
message_from_payload({})
7+
CC::Service::GitHubPullRequests::Presenter.new({}).success_message
88
)
99
end
1010

1111
def test_message_singular
1212
assert_equal(
1313
"Code Climate found 1 new issue and 1 fixed issue.",
14-
message_from_payload("fixed_issue_count" => 1, "new_issue_count" => 1)
14+
message_from_issue_counts("fixed" => 1, "new" => 1)
1515
)
1616
end
1717

1818
def test_message_plural
1919
assert_equal(
2020
"Code Climate found 2 new issues and 1 fixed issue.",
21-
message_from_payload("fixed_issue_count" => 1, "new_issue_count" => 2)
21+
message_from_issue_counts("fixed" => 1, "new" => 2)
2222
)
2323
end
2424

2525
def test_message_only_fixed
2626
assert_equal(
2727
"Code Climate found 1 fixed issue.",
28-
message_from_payload("fixed_issue_count" => 1, "new_issue_count" => 0)
28+
message_from_issue_counts("fixed" => 1, "new" => 0)
2929
)
3030
end
3131

3232
def test_message_only_new
3333
assert_equal(
3434
"Code Climate found 3 new issues.",
35-
message_from_payload("fixed_issue_count" => 0, "new_issue_count" => 3)
35+
message_from_issue_counts("fixed" => 0, "new" => 3)
3636
)
3737
end
3838

3939
def test_message_no_new_or_fixed
4040
assert_equal(
4141
"Code Climate didn't find any new or fixed issues.",
42-
message_from_payload("fixed_issue_count" => 0, "new_issue_count" => 0)
42+
message_from_issue_counts("fixed" => 0, "new" => 0)
4343
)
4444
end
4545

4646
private
4747

48-
def message_from_payload(payload)
48+
def message_from_issue_counts(issue_counts)
49+
payload = { "issue_comparison_counts" => issue_counts }
4950
CC::Service::GitHubPullRequests::Presenter.new(payload).success_message
5051
end
5152
end

test/github_pull_requests_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def test_pull_request_status_success_detailed
2424
github_slug: "pbrisbin/foo",
2525
commit_sha: "abc123",
2626
state: "success",
27-
new_issue_count: 1,
28-
fixed_issue_count: 2,
27+
issue_comparison_counts: {
28+
"fixed" => 2,
29+
"new" => 1,
30+
}
2931
})
3032
end
3133

0 commit comments

Comments
 (0)