codeclimate-services 1.11.0 → 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: 849571797dc28b6279e4281c3d1b5e356a9fc8150845690d82eced4fc0c000c1
4
- data.tar.gz: e944d253acde61ff799b0f07f31fb8d8aca97eda479351ff304ab8188b769dfc
3
+ metadata.gz: 9857632046cf9409d85f8ff2429efabf13c6eb5ab1300023d52407dc381deac0
4
+ data.tar.gz: 65fd4acdcc300cf00472ac8c8df740d0ec75dd382014a8963117680393629578
5
5
  SHA512:
6
- metadata.gz: 6ef756b1698fba1341bac6e6f05b4fdbd1286ae0afc14320245a89938392d9bfd2871035a09b9acf5529231da28f2ab955df4e11a30b5ea70941f6e12873b883
7
- data.tar.gz: 7795015fad0cb95435b0a1492b90438534b0821f698715dc0d986f845a6d4c6726aec744ed9f62063e178e107579b8771f8ac85914314488683c0bc65732784b
6
+ metadata.gz: 51e15698f1fbe51598067be6452db4b19ff6c4f913392ef172a772d58cb2c548805f569d34f11c74cb9ab486937cc75395104ffc082966b3a2edd7ee5866d832
7
+ data.tar.gz: 758fea2bc59978563b7a133affb1c8fd1d63d94250e88bbcabcd1d945a406c76845065abe7f249bd4ba33c4249b6620dd129d7ccfb8288a00297aa2309426b0a
@@ -0,0 +1,26 @@
1
+ version: 2.0
2
+ jobs:
3
+ test:
4
+ environment:
5
+ CC_TEST_REPORTER_ID: ad21bc049a323138b0a88086069115e9df6dba417912095b7bb17b7a65fc6182
6
+ docker:
7
+ - image: "circleci/ruby:2.7.5"
8
+ working_directory: ~/codeclimate/codeclimate-services
9
+ steps:
10
+ - checkout
11
+ - run:
12
+ name: Setup Coverage
13
+ command: |
14
+ (curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > cc-test-reporter && chmod +x ./cc-test-reporter) || echo "Couldn't download test reporter"
15
+ - run: bundle install && bundle exec rake
16
+ - persist_to_workspace:
17
+ root: .
18
+ paths:
19
+ - coverage
20
+ - run: ./cc-test-reporter after-build --exit-code $? || echo "Send coverage skipped..."
21
+
22
+ workflows:
23
+ version: 2
24
+ test:
25
+ jobs:
26
+ - test
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.4
1
+ 2.7.5
data/Gemfile CHANGED
@@ -7,5 +7,4 @@ gem "pry"
7
7
 
8
8
  group :test do
9
9
  gem "simplecov"
10
- gem "codeclimate-test-reporter", "~> 1.0.0"
11
10
  end
data/README.md CHANGED
@@ -131,6 +131,18 @@ and always return a hash of `{ ok: true|false, message: "String (HTML ok)" }`.
131
131
 
132
132
  When you open your PR, please include an image for your service.
133
133
 
134
+ ## Release
135
+
136
+ 1. Bump the version on `lib/cc/services/version`
137
+ 2. A gem owner developer should run the following: (check owners here https://rubygems.org/gems/codeclimate-services)
138
+ ```shell
139
+ bundle install
140
+ gem build codeclimate-services.gemspec
141
+ gem push codeclimate-services-<VERSION>.gem
142
+ git tag v<VERSION>
143
+ git push origin master --tags
144
+ ```
145
+
134
146
  ## License
135
147
 
136
148
  See LICENSE.txt. This incorporates code from bugsnag-notification-plugins and
@@ -36,9 +36,11 @@ module CC
36
36
  def coverage_message
37
37
  message = "#{formatted_percent(@covered_percent)}%"
38
38
 
39
- if @covered_percent_delta > 0
39
+ return message if @covered_percent_delta.nil?
40
+
41
+ if @covered_percent_delta.round(2) > 0
40
42
  message += " (+#{formatted_percent(@covered_percent_delta)}%)"
41
- elsif @covered_percent_delta < 0
43
+ elsif @covered_percent_delta.round(2) < 0
42
44
  message += " (#{formatted_percent(@covered_percent_delta)}%)"
43
45
  end
44
46
 
@@ -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
@@ -19,7 +19,7 @@ class CC::Service::Formatter < SimpleDelegator
19
19
  end
20
20
 
21
21
  def message_prefix
22
- prefix = options.fetch(:prefix, "").to_s
22
+ prefix = (options[:prefix] || "").to_s
23
23
 
24
24
  if options[:prefix_with_repo]
25
25
  prefix << "[#{repo_name}]"
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
@@ -3,7 +3,7 @@ require "base64"
3
3
  class CC::Service::Jira < CC::Service
4
4
  class Config < CC::Service::Config
5
5
  attribute :domain, Axiom::Types::String,
6
- description: "Your JIRA host domain (e.g. yourjira.com:PORT, please exclude https://)"
6
+ description: "Your JIRA host domain (e.g. yourjira.com[:PORT], please exclude https:// and only add PORT if you are using a different port number to access your own server that is not the default)"
7
7
 
8
8
  attribute :username, Axiom::Types::String,
9
9
  description: "Must exactly match the 'username' that appears on your JIRA profile page."
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Services
3
- VERSION = "1.11.0".freeze
3
+ VERSION = "1.11.3".freeze
4
4
  end
5
5
  end
@@ -30,12 +30,20 @@ describe CC::Service::PullRequestsPresenter, type: :service do
30
30
  expect("85%").to eq(build_presenter({}, "covered_percent" => 85, "covered_percent_delta" => 0).coverage_message)
31
31
  end
32
32
 
33
+ it "message coverage without delta" do
34
+ expect("85%").to eq(build_presenter({}, "covered_percent" => 85, "covered_percent_delta" => nil).coverage_message)
35
+ end
36
+
37
+ it "message coverage the same when rounded" do
38
+ expect("85%").to eq(build_presenter({}, "covered_percent" => 85, "covered_percent_delta" => 0.0005).coverage_message)
39
+ end
40
+
33
41
  it "message coverage up" do
34
42
  expect("85.5% (+2.46%)").to eq(build_presenter({}, "covered_percent" => 85.5, "covered_percent_delta" => 2.4567).coverage_message)
35
43
  end
36
44
 
37
45
  it "message coverage down" do
38
- expect("85.35% (-3%)").to eq( build_presenter({}, "covered_percent" => 85.348, "covered_percent_delta" => -3.0).coverage_message)
46
+ expect("85.35% (-3%)").to eq(build_presenter({}, "covered_percent" => 85.348, "covered_percent_delta" => -3.0).coverage_message)
39
47
  end
40
48
 
41
49
  it "message approved" do
@@ -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
@@ -0,0 +1,21 @@
1
+ describe CC::Service::Formatter do
2
+
3
+ class TestFormatter < described_class
4
+ def format_test
5
+ message = message_prefix
6
+ message << "This is a test"
7
+ end
8
+ end
9
+
10
+ FakeService = Struct.new(:receive)
11
+
12
+ it "supports passing nil as prefix" do
13
+ formatter = TestFormatter.new(
14
+ FakeService.new(:some_result),
15
+ prefix: nil,
16
+ prefix_with_repo: false,
17
+ )
18
+
19
+ expect(formatter.format_test).to eq("This is a test")
20
+ end
21
+ 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.0
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: 2018-07-11 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
@@ -129,6 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".circleci/config.yml"
132
133
  - ".codeclimate.yml"
133
134
  - ".gitignore"
134
135
  - ".rspec"
@@ -144,7 +145,6 @@ files:
144
145
  - bin/nokogiri
145
146
  - bin/pry
146
147
  - bin/rake
147
- - circle.yml
148
148
  - codeclimate-services.gemspec
149
149
  - config/cacert.pem
150
150
  - config/load.rb
@@ -194,10 +194,12 @@ 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
200
201
  - spec/cc/service/flowdock_spec.rb
202
+ - spec/cc/service/formatter_spec.rb
201
203
  - spec/cc/service/github_issues_spec.rb
202
204
  - spec/cc/service/github_pull_requests_spec.rb
203
205
  - spec/cc/service/gitlab_merge_requests_spec.rb
@@ -237,8 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
239
  - !ruby/object:Gem::Version
238
240
  version: '0'
239
241
  requirements: []
240
- rubyforge_project:
241
- rubygems_version: 2.7.7
242
+ rubygems_version: 3.3.7
242
243
  signing_key:
243
244
  specification_version: 4
244
245
  summary: Service classes for Code Climate
@@ -247,10 +248,12 @@ 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
253
255
  - spec/cc/service/flowdock_spec.rb
256
+ - spec/cc/service/formatter_spec.rb
254
257
  - spec/cc/service/github_issues_spec.rb
255
258
  - spec/cc/service/github_pull_requests_spec.rb
256
259
  - spec/cc/service/gitlab_merge_requests_spec.rb
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- test:
2
- override:
3
- - bundle exec rake && bundle exec codeclimate-test-reporter