codeclimate-services 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cc/presenters/pull_requests_presenter.rb +15 -2
- data/lib/cc/services/github_pull_requests.rb +16 -44
- data/lib/cc/services/version.rb +1 -1
- data/pull_request_test.rb +0 -1
- data/service_test.rb +1 -1
- data/test/github_pull_requests_test.rb +19 -67
- data/test/presenters/pull_requests_presenter_test.rb +23 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5df730afefd8e53147faaab840a08cc8a7b8a6e2
|
4
|
+
data.tar.gz: e3228551b4e7acae238ee5da6fbb3f46ea2074e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d40a0916c6ebf0d981f0731db49d25c1c748dc296efbd2d04e749b4fa848644e423cb3d157afd57dbbeeb825112be3ab525b67ca22549b27c476fb6ff84b545c
|
7
|
+
data.tar.gz: a8e1a740ba27e3c743b80e4d1245d5bc6b0a72173f799608eb57c64b36a876a8f6579338176fafebcd6ef1ca85cefb0c8c6181ac2769182cc6f4fbebf2493cf6
|
@@ -12,6 +12,7 @@ module CC
|
|
12
12
|
end
|
13
13
|
|
14
14
|
@covered_percent = payload["covered_percent"]
|
15
|
+
@covered_percent_delta = payload["covered_percent_delta"]
|
15
16
|
end
|
16
17
|
|
17
18
|
def error_message
|
@@ -26,8 +27,16 @@ module CC
|
|
26
27
|
"Code Climate has skipped analysis of this commit."
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
-
|
30
|
+
def coverage_message
|
31
|
+
message = "#{formatted_percent(@covered_percent)}% test coverage"
|
32
|
+
|
33
|
+
if @covered_percent_delta.positive?
|
34
|
+
message += " (+#{formatted_percent(@covered_percent_delta)}%)"
|
35
|
+
elsif @covered_percent_delta.negative?
|
36
|
+
message += " (#{formatted_percent(@covered_percent_delta)}%)"
|
37
|
+
end
|
38
|
+
|
39
|
+
message
|
31
40
|
end
|
32
41
|
|
33
42
|
def success_message
|
@@ -64,6 +73,10 @@ module CC
|
|
64
73
|
[formatted_new_issues, formatted_fixed_issues].compact.to_sentence
|
65
74
|
end
|
66
75
|
|
76
|
+
def formatted_percent(value)
|
77
|
+
"%g" % ("%.2f" % value)
|
78
|
+
end
|
79
|
+
|
67
80
|
def issue_counts
|
68
81
|
[@new_count, @fixed_count]
|
69
82
|
end
|
@@ -5,14 +5,6 @@ class CC::Service::GitHubPullRequests < CC::Service
|
|
5
5
|
attribute :oauth_token, Axiom::Types::String,
|
6
6
|
label: "OAuth Token",
|
7
7
|
description: "A personal OAuth token with permissions for the repo."
|
8
|
-
attribute :update_status, Axiom::Types::Boolean,
|
9
|
-
label: "Update analysis status?",
|
10
|
-
description: "Update the pull request status after analyzing?",
|
11
|
-
default: true
|
12
|
-
attribute :update_coverage_status, Axiom::Types::Boolean,
|
13
|
-
label: "Update coverage status?",
|
14
|
-
description: "Update the pull request status with test coverage reports?",
|
15
|
-
default: false
|
16
8
|
attribute :base_url, Axiom::Types::String,
|
17
9
|
label: "Github API Base URL",
|
18
10
|
description: "Base URL for the Github API",
|
@@ -34,38 +26,30 @@ class CC::Service::GitHubPullRequests < CC::Service
|
|
34
26
|
def receive_test
|
35
27
|
setup_http
|
36
28
|
|
37
|
-
|
38
|
-
receive_test_status
|
39
|
-
else
|
40
|
-
simple_failure("Nothing happened")
|
41
|
-
end
|
29
|
+
receive_test_status
|
42
30
|
end
|
43
31
|
|
44
32
|
def receive_pull_request
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@response = simple_failure("Unknown state")
|
53
|
-
end
|
33
|
+
setup_http
|
34
|
+
state = @payload["state"]
|
35
|
+
|
36
|
+
if %w[pending success failure skipped error].include?(state)
|
37
|
+
send("update_status_#{state}")
|
38
|
+
else
|
39
|
+
@response = simple_failure("Unknown state")
|
54
40
|
end
|
55
41
|
|
56
42
|
response
|
57
43
|
end
|
58
44
|
|
59
45
|
def receive_pull_request_coverage
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
@response = simple_failure("Unknown state")
|
68
|
-
end
|
46
|
+
setup_http
|
47
|
+
state = @payload["state"]
|
48
|
+
|
49
|
+
if state == "success"
|
50
|
+
update_coverage_status_success
|
51
|
+
else
|
52
|
+
@response = simple_failure("Unknown state")
|
69
53
|
end
|
70
54
|
|
71
55
|
response
|
@@ -73,18 +57,6 @@ class CC::Service::GitHubPullRequests < CC::Service
|
|
73
57
|
|
74
58
|
private
|
75
59
|
|
76
|
-
def update_status?
|
77
|
-
effective_boolean?(config.update_status)
|
78
|
-
end
|
79
|
-
|
80
|
-
def update_coverage_status?
|
81
|
-
effective_boolean?(config.update_coverage_status)
|
82
|
-
end
|
83
|
-
|
84
|
-
def effective_boolean?(value)
|
85
|
-
[true, "1"].include?(value)
|
86
|
-
end
|
87
|
-
|
88
60
|
def simple_failure(message)
|
89
61
|
{ ok: false, message: message }
|
90
62
|
end
|
@@ -102,7 +74,7 @@ private
|
|
102
74
|
end
|
103
75
|
|
104
76
|
def update_coverage_status_success
|
105
|
-
update_status("success", presenter.
|
77
|
+
update_status("success", presenter.coverage_message, "#{config.context}/coverage")
|
106
78
|
end
|
107
79
|
|
108
80
|
def update_status_failure
|
data/lib/cc/services/version.rb
CHANGED
data/pull_request_test.rb
CHANGED
data/service_test.rb
CHANGED
@@ -83,4 +83,4 @@ ServiceTest.new(CC::Service::Slack, :webhook_url).test
|
|
83
83
|
ServiceTest.new(CC::Service::Flowdock, :api_token).test
|
84
84
|
ServiceTest.new(CC::Service::Jira, :username, :password, :domain, :project_id).test
|
85
85
|
ServiceTest.new(CC::Service::Asana, :api_key, :workspace_id, :project_id).test
|
86
|
-
ServiceTest.new(CC::Service::GitHubPullRequests, :oauth_token
|
86
|
+
ServiceTest.new(CC::Service::GitHubPullRequests, :oauth_token).test({ github_slug: "codeclimate/codeclimate" })
|
@@ -7,7 +7,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
7
7
|
"description" => /is analyzing/,
|
8
8
|
})
|
9
9
|
|
10
|
-
receive_pull_request({
|
10
|
+
receive_pull_request({}, {
|
11
11
|
github_slug: "pbrisbin/foo",
|
12
12
|
commit_sha: "abc123",
|
13
13
|
state: "pending",
|
@@ -21,7 +21,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
21
21
|
})
|
22
22
|
|
23
23
|
receive_pull_request(
|
24
|
-
{
|
24
|
+
{},
|
25
25
|
{
|
26
26
|
github_slug: "pbrisbin/foo",
|
27
27
|
commit_sha: "abc123",
|
@@ -37,7 +37,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
37
37
|
})
|
38
38
|
|
39
39
|
receive_pull_request(
|
40
|
-
{
|
40
|
+
{ },
|
41
41
|
{
|
42
42
|
github_slug: "pbrisbin/foo",
|
43
43
|
commit_sha: "abc123",
|
@@ -52,7 +52,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
52
52
|
"description" => /found 2 new issues and 1 fixed issue/,
|
53
53
|
})
|
54
54
|
|
55
|
-
receive_pull_request({
|
55
|
+
receive_pull_request({}, {
|
56
56
|
github_slug: "pbrisbin/foo",
|
57
57
|
commit_sha: "abc123",
|
58
58
|
state: "success",
|
@@ -65,7 +65,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
65
65
|
"description" => "Code Climate encountered an error attempting to analyze this pull request.",
|
66
66
|
})
|
67
67
|
|
68
|
-
receive_pull_request({
|
68
|
+
receive_pull_request({}, {
|
69
69
|
github_slug: "pbrisbin/foo",
|
70
70
|
commit_sha: "abc123",
|
71
71
|
state: "error",
|
@@ -79,7 +79,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
79
79
|
"description" => "descriptive message",
|
80
80
|
})
|
81
81
|
|
82
|
-
receive_pull_request({
|
82
|
+
receive_pull_request({}, {
|
83
83
|
github_slug: "pbrisbin/foo",
|
84
84
|
commit_sha: "abc123",
|
85
85
|
state: "error",
|
@@ -93,75 +93,45 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
93
93
|
"description" => /skipped analysis/,
|
94
94
|
})
|
95
95
|
|
96
|
-
receive_pull_request({
|
96
|
+
receive_pull_request({}, {
|
97
97
|
github_slug: "pbrisbin/foo",
|
98
98
|
commit_sha: "abc123",
|
99
99
|
state: "skipped",
|
100
100
|
})
|
101
101
|
end
|
102
102
|
|
103
|
-
def
|
103
|
+
def test_pull_request_coverage_status
|
104
104
|
expect_status_update("pbrisbin/foo", "abc123", {
|
105
105
|
"state" => "success",
|
106
|
-
"description" => "
|
106
|
+
"description" => "87% test coverage (+2%)",
|
107
107
|
})
|
108
108
|
|
109
|
-
receive_pull_request_coverage({
|
109
|
+
receive_pull_request_coverage({},
|
110
110
|
github_slug: "pbrisbin/foo",
|
111
111
|
commit_sha: "abc123",
|
112
112
|
state: "success",
|
113
|
-
covered_percent: 87
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
def test_no_status_update_for_skips_when_update_status_config_is_falsey
|
118
|
-
# With no POST expectation, test will fail if request is made.
|
119
|
-
|
120
|
-
receive_pull_request({ update_status: false }, {
|
121
|
-
github_slug: "pbrisbin/foo",
|
122
|
-
commit_sha: "abc123",
|
123
|
-
state: "skipped",
|
124
|
-
})
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_no_status_update_for_pending_when_update_status_config_is_falsey
|
128
|
-
# With no POST expectation, test will fail if request is made.
|
129
|
-
|
130
|
-
receive_pull_request({ update_status: false }, {
|
131
|
-
github_slug: "pbrisbin/foo",
|
132
|
-
commit_sha: "abc123",
|
133
|
-
state: "pending",
|
134
|
-
})
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_no_status_update_for_error_when_update_status_config_is_falsey
|
138
|
-
# With no POST expectation, test will fail if request is made.
|
139
|
-
|
140
|
-
receive_pull_request({ update_status: false }, {
|
141
|
-
github_slug: "pbrisbin/foo",
|
142
|
-
commit_sha: "abc123",
|
143
|
-
state: "error",
|
144
|
-
message: nil,
|
145
|
-
})
|
113
|
+
covered_percent: 87,
|
114
|
+
covered_percent_delta: 2.0,
|
115
|
+
)
|
146
116
|
end
|
147
117
|
|
148
118
|
def test_pull_request_status_test_success
|
149
119
|
@stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |env| [422, {}, ""] }
|
150
120
|
|
151
|
-
assert receive_test({
|
121
|
+
assert receive_test({}, { github_slug: "pbrisbin/foo" })[:ok], "Expected test of pull request to be true"
|
152
122
|
end
|
153
123
|
|
154
124
|
def test_pull_request_status_test_doesnt_blow_up_when_unused_keys_present_in_config
|
155
125
|
@stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |env| [422, {}, ""] }
|
156
126
|
|
157
|
-
assert receive_test({
|
127
|
+
assert receive_test({ wild_flamingo: true }, { github_slug: "pbrisbin/foo" })[:ok], "Expected test of pull request to be true"
|
158
128
|
end
|
159
129
|
|
160
130
|
def test_pull_request_status_test_failure
|
161
131
|
@stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |env| [401, {}, ""] }
|
162
132
|
|
163
133
|
assert_raises(CC::Service::HTTPError) do
|
164
|
-
receive_test({
|
134
|
+
receive_test({}, { github_slug: "pbrisbin/foo" })
|
165
135
|
end
|
166
136
|
end
|
167
137
|
|
@@ -171,19 +141,13 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
171
141
|
assert_equal({ ok: false, message: "Unknown state" }, response)
|
172
142
|
end
|
173
143
|
|
174
|
-
def test_pull_request_nothing_happened
|
175
|
-
response = receive_pull_request({ update_status: false }, { state: "success" })
|
176
|
-
|
177
|
-
assert_equal({ ok: false, message: "Nothing happened" }, response)
|
178
|
-
end
|
179
|
-
|
180
144
|
def test_different_base_url
|
181
145
|
@stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") do |env|
|
182
146
|
assert env[:url].to_s == "http://example.com/repos/pbrisbin/foo/statuses/#{"0" * 40}"
|
183
147
|
[422, { "x-oauth-scopes" => "gist, user, repo" }, ""]
|
184
148
|
end
|
185
149
|
|
186
|
-
assert receive_test({
|
150
|
+
assert receive_test({ base_url: "http://example.com" }, { github_slug: "pbrisbin/foo" })[:ok], "Expected test of pull request to be true"
|
187
151
|
end
|
188
152
|
|
189
153
|
def test_default_context
|
@@ -192,7 +156,7 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
192
156
|
"state" => "pending",
|
193
157
|
})
|
194
158
|
|
195
|
-
response = receive_pull_request({
|
159
|
+
response = receive_pull_request({}, {
|
196
160
|
github_slug: "gordondiggs/ellis",
|
197
161
|
commit_sha: "abc123",
|
198
162
|
state: "pending",
|
@@ -205,25 +169,13 @@ class TestGitHubPullRequests < CC::Service::TestCase
|
|
205
169
|
"state" => "pending",
|
206
170
|
})
|
207
171
|
|
208
|
-
response = receive_pull_request({ context: "sup"
|
172
|
+
response = receive_pull_request({ context: "sup" }, {
|
209
173
|
github_slug: "gordondiggs/ellis",
|
210
174
|
commit_sha: "abc123",
|
211
175
|
state: "pending",
|
212
176
|
})
|
213
177
|
end
|
214
178
|
|
215
|
-
def test_config_coerce_bool_true
|
216
|
-
c = CC::Service::GitHubPullRequests::Config.new(oauth_token: "a1b2c3", update_status: "1")
|
217
|
-
assert c.valid?
|
218
|
-
assert_equal true, c.update_status
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_config_coerce_bool_false
|
222
|
-
c = CC::Service::GitHubPullRequests::Config.new(oauth_token: "a1b2c3", update_status: "0")
|
223
|
-
assert c.valid?
|
224
|
-
assert_equal false, c.update_status
|
225
|
-
end
|
226
|
-
|
227
179
|
private
|
228
180
|
|
229
181
|
def expect_status_update(repo, commit_sha, params)
|
@@ -37,13 +37,34 @@ class TestPullRequestsPresenter < CC::Service::TestCase
|
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_message_coverage_same
|
41
|
+
assert_equal(
|
42
|
+
"85% test coverage",
|
43
|
+
build_presenter({}, "covered_percent" => 85, "covered_percent_delta" => 0).coverage_message
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_message_coverage_up
|
48
|
+
assert_equal(
|
49
|
+
"85.5% test coverage (+2.46%)",
|
50
|
+
build_presenter({}, "covered_percent" => 85.5, "covered_percent_delta" => 2.4567).coverage_message
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_message_coverage_down
|
55
|
+
assert_equal(
|
56
|
+
"85.35% test coverage (-3%)",
|
57
|
+
build_presenter({}, "covered_percent" => 85.348, "covered_percent_delta" => -3.0).coverage_message
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
40
61
|
private
|
41
62
|
|
42
63
|
def build_payload(issue_counts)
|
43
64
|
{ "issue_comparison_counts" => issue_counts }
|
44
65
|
end
|
45
66
|
|
46
|
-
def build_presenter(issue_counts)
|
47
|
-
CC::Service::PullRequestsPresenter.new(build_payload(issue_counts))
|
67
|
+
def build_presenter(issue_counts, payload = {})
|
68
|
+
CC::Service::PullRequestsPresenter.new(build_payload(issue_counts).merge(payload))
|
48
69
|
end
|
49
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeclimate-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|