codeclimate-services 1.11.2 → 1.11.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96ac3fb2929dbad8aadc4a01e46ae15dfdbd0f624da568dd171349b664cb9da2
4
- data.tar.gz: de09b581fb3a7ec8c7d597d65f06d832acc8f00ecbbde05cc2a4a340ea6e75b2
3
+ metadata.gz: 9857632046cf9409d85f8ff2429efabf13c6eb5ab1300023d52407dc381deac0
4
+ data.tar.gz: 65fd4acdcc300cf00472ac8c8df740d0ec75dd382014a8963117680393629578
5
5
  SHA512:
6
- metadata.gz: 9e75e38ea1dbcda5c960c5310a98ab6cade92b8ec51a54a3a4dfb43249ef04f35d318f2733f51e80920d337ed36c77cfbae14ca60ac5efbcafae68da6e3f1df5
7
- data.tar.gz: 5ef15601e7864fd5a4287ac48658bd9e2e60847939e19c1a16f9bacc4836ee1d5eec9363b9648708edffdfa0678f662747e0b80b70792321572c52d0f3cc99ca
6
+ metadata.gz: 51e15698f1fbe51598067be6452db4b19ff6c4f913392ef172a772d58cb2c548805f569d34f11c74cb9ab486937cc75395104ffc082966b3a2edd7ee5866d832
7
+ data.tar.gz: 758fea2bc59978563b7a133affb1c8fd1d63d94250e88bbcabcd1d945a406c76845065abe7f249bd4ba33c4249b6620dd129d7ccfb8288a00297aa2309426b0a
@@ -6,29 +6,15 @@ class CC::PullRequests < CC::Service
6
6
  end
7
7
 
8
8
  def receive_pull_request
9
- setup_http
10
- state = @payload["state"]
11
-
12
- if %w[pending success failure skipped error].include?(state) && report_status?
13
- send("update_status_#{state}")
14
- else
15
- @response = simple_failure("Unknown state")
16
- end
17
-
18
- response
9
+ receive_request(%w[pending success failure skipped error], :update_status)
19
10
  end
20
11
 
21
12
  def receive_pull_request_coverage
22
- setup_http
23
- state = @payload["state"]
24
-
25
- if state == "success" && report_status?
26
- update_coverage_status_success
27
- else
28
- @response = simple_failure("Unknown state")
29
- end
13
+ receive_request("success", :update_coverage_status)
14
+ end
30
15
 
31
- response
16
+ def receive_pull_request_diff_coverage
17
+ receive_request("skipped", :update_diff_coverage_status)
32
18
  end
33
19
 
34
20
  private
@@ -57,6 +43,10 @@ class CC::PullRequests < CC::Service
57
43
  raise NotImplementedError
58
44
  end
59
45
 
46
+ def update_diff_coverage_status_skipped
47
+ raise NotImplementedError
48
+ end
49
+
60
50
  def update_status_failure
61
51
  raise NotImplementedError
62
52
  end
@@ -91,6 +81,19 @@ class CC::PullRequests < CC::Service
91
81
  end
92
82
  end
93
83
 
84
+ def receive_request(*permitted_statuses, call_method)
85
+ setup_http
86
+ state = @payload["state"]
87
+
88
+ if permitted_statuses.flatten.include?(state) && report_status?
89
+ send(call_method.to_s + "_#{state}")
90
+ else
91
+ @response = simple_failure("Unknown state")
92
+ end
93
+
94
+ response
95
+ end
96
+
94
97
  def presenter
95
98
  CC::Service::PullRequestsPresenter.new(@payload)
96
99
  end
data/lib/cc/service.rb CHANGED
@@ -36,6 +36,7 @@ module CC
36
36
  issue
37
37
  pull_request
38
38
  pull_request_coverage
39
+ pull_request_diff_coverage
39
40
  quality
40
41
  snapshot
41
42
  test
@@ -71,6 +71,11 @@ class CC::Service::GitHubPullRequests < CC::PullRequests
71
71
  update_status("success", presenter.coverage_message, "#{config.context}/coverage")
72
72
  end
73
73
 
74
+ def update_diff_coverage_status_skipped
75
+ update_status("success", presenter.skipped_message, "#{config.context}/diff-coverage")
76
+ update_status("success", presenter.skipped_message, "#{config.context}/total-coverage")
77
+ end
78
+
74
79
  def update_status_failure
75
80
  update_status("failure", presenter.success_message)
76
81
  end
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Services
3
- VERSION = "1.11.2".freeze
3
+ VERSION = "1.11.3".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ describe CC::PullRequests do
4
+ shared_examples "receive method" do
5
+ before do
6
+ allow(instance).to receive(:report_status?).and_return(true)
7
+ expect(instance).to receive(:setup_http)
8
+ end
9
+
10
+ context "when the status is valid" do
11
+ let(:instance) { CC::PullRequests.new({}, name: "test", state: payload_status) }
12
+ let(:response) do
13
+ {
14
+ ok: true,
15
+ state: 201,
16
+ message: "Success",
17
+ }
18
+ end
19
+
20
+ it "calls the corresponding method" do
21
+ expect(instance).to receive(expected_method_name) do
22
+ instance.instance_variable_set(:@response, response)
23
+ end
24
+ result = instance.send(method_to_call)
25
+
26
+ expect(result).to eq(response)
27
+ end
28
+
29
+ context "when report_status? is false" do
30
+ before { expect(instance).to receive(:report_status?).and_return(false) }
31
+
32
+ it "returns unknown status message" do
33
+ expect(instance).not_to receive(expected_method_name)
34
+ result = instance.send(method_to_call)
35
+
36
+ expect(result).to eq({ ok: false, message: "Unknown state" })
37
+ end
38
+ end
39
+ end
40
+
41
+ context "when the status is not valid" do
42
+ let(:instance) { CC::PullRequests.new({}, name: "test", status: "invalid_status") }
43
+
44
+ it "returns unknown status message" do
45
+ expect(instance).not_to receive(expected_method_name)
46
+ result = instance.send(method_to_call)
47
+
48
+ expect(result).to eq({ ok: false, message: "Unknown state" })
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#receive_test" do
54
+ let(:instance) { CC::PullRequests.new({}, name: "test") }
55
+
56
+ before do
57
+ expect(instance).to receive(:base_status_url) do |param|
58
+ "some_url" + param
59
+ end
60
+ expect(instance).to receive(:setup_http)
61
+ end
62
+
63
+ it "makes a raw http test post" do
64
+ expect_any_instance_of(CC::Service::HTTP).to receive(:raw_post).with(
65
+ "some_url" + ("0" * 40),
66
+ { state: "success" }.to_json
67
+ )
68
+
69
+ instance.receive_test
70
+ end
71
+
72
+ context "when raising an HTTPError" do
73
+ context "when message is equal to test_status_code" do
74
+ it "returns an ok message" do
75
+ expect(instance).to receive(:test_status_code) { 777 }
76
+ expect(instance).to receive(:raw_post).
77
+ and_raise(CC::Service::HTTPError.new("error", status: 777))
78
+
79
+ result = instance.receive_test
80
+ expect(result).to include(
81
+ ok: true,
82
+ status: 777,
83
+ message: "Access token is valid"
84
+ )
85
+ end
86
+ end
87
+
88
+ context "when message is different than test_status_code" do
89
+ it "raises the error" do
90
+ expect(instance).to receive(:test_status_code) { 777 }
91
+ expect(instance).to receive(:raw_post).
92
+ and_raise(CC::Service::HTTPError.new("error", status: 000))
93
+
94
+ expect { instance.receive_test }.to raise_error
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "#receive_pull_request" do
101
+ let(:payload_status) { "skipped" }
102
+ let(:expected_method_name) { :update_status_skipped }
103
+ let(:method_to_call) { :receive_pull_request }
104
+
105
+ it_behaves_like "receive method"
106
+ end
107
+
108
+ describe "#receive_pull_request_coverage" do
109
+ let(:payload_status) { "success" }
110
+ let(:expected_method_name) { :update_coverage_status_success }
111
+ let(:method_to_call) { :receive_pull_request_coverage }
112
+
113
+ it_behaves_like "receive method"
114
+ end
115
+
116
+ describe "#receive_pull_request_diff_coverage" do
117
+ let(:payload_status) { "skipped" }
118
+ let(:expected_method_name) { :update_diff_coverage_status_skipped }
119
+ let(:method_to_call) { :receive_pull_request_diff_coverage }
120
+
121
+ it_behaves_like "receive method"
122
+ end
123
+ end
@@ -82,6 +82,18 @@ describe CC::Service::GitHubPullRequests, type: :service do
82
82
  covered_percent_delta: 2.0)
83
83
  end
84
84
 
85
+ it "pull request diff coverage skipped" do
86
+ expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
87
+ "description" => /skipped analysis/, "context" => /diff-coverage/)
88
+ expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
89
+ "description" => /skipped analysis/, "context" => /total-coverage/)
90
+
91
+ receive_pull_request_diff_coverage({},
92
+ github_slug: "pbrisbin/foo",
93
+ commit_sha: "abc123",
94
+ state: "skipped")
95
+ end
96
+
85
97
  it "pull request status test success" do
86
98
  http_stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |_env| [422, {}, ""] }
87
99
 
@@ -213,6 +225,14 @@ describe CC::Service::GitHubPullRequests, type: :service do
213
225
  )
214
226
  end
215
227
 
228
+ def receive_pull_request_diff_coverage(config, event_data)
229
+ service_receive(
230
+ CC::Service::GitHubPullRequests,
231
+ { oauth_token: "123" }.merge(config),
232
+ { name: "pull_request_diff_coverage" }.merge(event_data),
233
+ )
234
+ end
235
+
216
236
  def receive_test(config, event_data = {})
217
237
  service_receive(
218
238
  CC::Service::GitHubPullRequests,
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.11.2
4
+ version: 1.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-10 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -194,6 +194,7 @@ files:
194
194
  - spec/axiom/types/token_spec.rb
195
195
  - spec/cc/formatters/snapshot_formatter_spec.rb
196
196
  - spec/cc/presenters/pull_requests_presenter_spec.rb
197
+ - spec/cc/pull_requests_spec.rb
197
198
  - spec/cc/resolve_spec.rb
198
199
  - spec/cc/service/asana_spec.rb
199
200
  - spec/cc/service/campfire_spec.rb
@@ -247,6 +248,7 @@ test_files:
247
248
  - spec/axiom/types/token_spec.rb
248
249
  - spec/cc/formatters/snapshot_formatter_spec.rb
249
250
  - spec/cc/presenters/pull_requests_presenter_spec.rb
251
+ - spec/cc/pull_requests_spec.rb
250
252
  - spec/cc/resolve_spec.rb
251
253
  - spec/cc/service/asana_spec.rb
252
254
  - spec/cc/service/campfire_spec.rb