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

Commit 7b53cde

Browse files
author
Ian C. Anderson
committed
Fix load-order dependency
This fixes an `unitialized constant CC::Service::GitHubPullRequests`, which was happening if `CC::Service::GithubPullRequests::Presenter` was loaded before `CC::Service::GithubPullRequests`. Loading order is non-deterministic and can differ depending on OS, since services are loaded via `Dir[]`). Going forward, services that need a presenter class can require the presenter themselves.
1 parent b8111a7 commit 7b53cde

File tree

4 files changed

+68
-61
lines changed

4 files changed

+68
-61
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
module CC
2+
class Service
3+
class GitHubPullRequestsPresenter
4+
def initialize(payload, repo_config)
5+
issue_comparison_counts = payload["issue_comparison_counts"]
6+
7+
if issue_comparison_counts
8+
@fixed_count = issue_comparison_counts["fixed"]
9+
@new_count = issue_comparison_counts["new"]
10+
end
11+
12+
@repo_config = repo_config
13+
end
14+
15+
def success_message
16+
if @repo_config.pr_status_quality_stats?
17+
if both_issue_counts_zero?
18+
"Code Climate didn't find any new or fixed issues."
19+
else
20+
"Code Climate found #{formatted_issue_counts}."
21+
end
22+
else
23+
"Code Climate has analyzed this pull request."
24+
end
25+
end
26+
27+
private
28+
29+
def both_issue_counts_zero?
30+
issue_counts.all?(&:zero?)
31+
end
32+
33+
def formatted_fixed_issues
34+
if @fixed_count > 0
35+
"#{@fixed_count} fixed #{"issue".pluralize(@fixed_count)}"
36+
else
37+
nil
38+
end
39+
end
40+
41+
def formatted_new_issues
42+
if @new_count > 0
43+
"#{@new_count} new #{"issue".pluralize(@new_count)}"
44+
else
45+
nil
46+
end
47+
end
48+
49+
def formatted_issue_counts
50+
[formatted_new_issues, formatted_fixed_issues].compact.to_sentence
51+
end
52+
53+
def issue_counts
54+
[@new_count, @fixed_count]
55+
end
56+
57+
def issue_counts_in_payload?
58+
issue_counts.all?
59+
end
60+
end
61+
end
62+
end

lib/cc/services/github_pull_requests.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "cc/presenters/github_pull_requests_presenter"
2+
13
class CC::Service::GitHubPullRequests < CC::Service
24
class Config < CC::Service::Config
35
attribute :oauth_token, String,
@@ -74,7 +76,7 @@ def update_status_success
7476
end
7577

7678
def presenter
77-
CC::Service::GitHubPullRequests::Presenter.new(@payload, @repo_config)
79+
CC::Service::GitHubPullRequestsPresenter.new(@payload, @repo_config)
7880
end
7981

8082
def update_status_error

lib/cc/services/github_pull_requests_presenter.rb

Lines changed: 0 additions & 58 deletions
This file was deleted.

test/github_pull_requests_presenter_test.rb renamed to test/presenters/github_pull_requests_presenter_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require File.expand_path('../helper', __FILE__)
1+
require "helper"
2+
require "cc/presenters/github_pull_requests_presenter"
23

34
class TestGitHubPullRequestsPresenter < CC::Service::TestCase
45
def test_message_quality_stats_not_enabled
@@ -50,7 +51,7 @@ def build_payload(issue_counts)
5051
end
5152

5253
def build_presenter(quality_stats_enabled, issue_counts)
53-
CC::Service::GitHubPullRequests::Presenter.new(
54+
CC::Service::GitHubPullRequestsPresenter.new(
5455
build_payload(issue_counts),
5556
OpenStruct.new(pr_status_quality_stats?: quality_stats_enabled)
5657
)

0 commit comments

Comments
 (0)