codeclimate-services 1.11.1 → 1.11.4

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: 8980a3e6294016d7483aedd981ee4c54f56c45f8526274e9516013825d9f626a
4
- data.tar.gz: ef2aaaa203bc911dbb348b5e4f1d3e0b7b6a7eaab0e7857156e4318d6c6ac74b
3
+ metadata.gz: e49ecbb12d3d95c5fcf279a4d5a66042fff2349a034f864ca361c7b575e498b4
4
+ data.tar.gz: 1564c19d8878e7982e9a18fb66cc4ae954ec26a7cabaebf4e0e4f0f919316b49
5
5
  SHA512:
6
- metadata.gz: bcf20aee515217c99ab7d09ee592bba7b3ec16f732e9bd7ffd3698b18d3a6e5bab3ab7c6f5dcf1bb0806d6e0c4f4179b551de756a545a2d93ccaef0467e7b87d
7
- data.tar.gz: 3941929485b68f39e67ee5c02f03faad637e3273b16c87dc92c7b85fcf8c6025a17c40e62a1306b64b2d9ddc4d7d33e63ae4b8de5a59abd1c1d009415962673e
6
+ metadata.gz: 2e6a1864050ea867c58dfc8432f44a853f9563cba2bbf3a2bd9d33fee0bffcbf823115cd11811fc268bfec2049e3e002e594e916455a3a4a1839a2e52d4e34e7
7
+ data.tar.gz: c266bbdd933ed408284569eef1f628353dfc38f07b0d585bd85b3704396a924f0f1e01ab9018e4aee59d45afc8ec2a39cb6bd3e1ab45713eef5985f80f205153
data/.circleci/config.yml CHANGED
@@ -1,16 +1,57 @@
1
- version: 2
1
+ version: 2.0
2
+ init: &init
3
+ run:
4
+ name: init
5
+ command: |
6
+ echo '. .circleci/shared.bash' >> "$BASH_ENV"
2
7
 
3
8
  jobs:
4
9
  test:
5
- machine:
6
- docker_layer_caching: true
10
+ environment:
11
+ CC_TEST_REPORTER_ID: ad21bc049a323138b0a88086069115e9df6dba417912095b7bb17b7a65fc6182
12
+ docker:
13
+ - image: "circleci/ruby:2.7.5"
7
14
  working_directory: ~/codeclimate/codeclimate-services
8
15
  steps:
9
16
  - checkout
10
- - run: bundle install && bundle exec rake && bundle exec codeclimate-test-reporter
17
+ - run:
18
+ name: Setup Coverage
19
+ command: |
20
+ (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"
21
+ - run: bundle install && bundle exec rake
22
+ - persist_to_workspace:
23
+ root: .
24
+ paths:
25
+ - coverage
26
+ - run: ./cc-test-reporter after-build --exit-code $? || echo "Send coverage skipped..."
27
+
28
+ publish:
29
+ machine: true
30
+ steps:
31
+ - checkout
32
+ - *init
33
+ - run:
34
+ name: Install Hub dependency
35
+ command: install_hub
36
+ - run:
37
+ name: Login on RubyGems
38
+ command: login_to_rubygems
39
+ - run:
40
+ name: Publish new version
41
+ command: |
42
+ if [ `git diff --quiet HEAD~ VERSION; echo $?` -eq 1 ]; then
43
+ publish_new_version
44
+ fi
11
45
 
12
46
  workflows:
13
47
  version: 2
14
48
  test:
15
49
  jobs:
16
50
  - test
51
+ - publish:
52
+ requires:
53
+ - test
54
+ filters:
55
+ branches:
56
+ only:
57
+ - master
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+
3
+ set -exuo pipefail
4
+
5
+ VERSION=$(cat VERSION)
6
+
7
+ function install_hub() {
8
+ sudo apt update && sudo apt install -y git wget
9
+ url="$(wget -qO- https://api.github.com/repos/github/hub/releases/latest | tr '"' '\n' | grep '.*/download/.*/hub-linux-amd64-.*.tgz')"
10
+ wget -qO- "$url" | sudo tar -xzvf- -C /usr/bin --strip-components=2 --wildcards "*/bin/hub"
11
+ }
12
+
13
+ function login_to_rubygems() {
14
+ mkdir -p "$HOME/.gem"
15
+ touch "$HOME/.gem/credentials"
16
+ chmod 0600 "$HOME/.gem/credentials"
17
+ printf -- "---\n:rubygems_api_key: %s\n" "$GEM_HOST_API_KEY" > "$HOME/.gem/credentials"
18
+ }
19
+
20
+ function tag_version() {
21
+ GITHUB_TOKEN="${GITHUB_TOKEN}" hub release create -m "v${VERSION}" "v${VERSION}"
22
+ }
23
+
24
+
25
+ function publish_new_version() {
26
+ set +x
27
+ # Build and push gem
28
+ gem build ./*.gemspec
29
+ gem push ./*.gem
30
+
31
+ # Create gh tag
32
+ tag_version
33
+
34
+ set -x
35
+ }
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
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.11.4
@@ -5,7 +5,7 @@ require "cc/services/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "codeclimate-services"
8
- spec.version = CC::Services::VERSION
8
+ spec.version = CC::Services.version
9
9
  spec.authors = ["Bryan Helmkamp"]
10
10
  spec.email = ["bryan@brynary.com"]
11
11
  spec.summary = "Service classes for Code Climate"
@@ -6,29 +6,19 @@ 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"]
13
+ receive_request("success", :update_coverage_status)
14
+ end
24
15
 
25
- if state == "success" && report_status?
26
- update_coverage_status_success
27
- else
28
- @response = simple_failure("Unknown state")
29
- end
16
+ def receive_pull_request_diff_coverage
17
+ receive_request(%w[pending skipped], :update_diff_coverage_status)
18
+ end
30
19
 
31
- response
20
+ def receive_pull_request_total_coverage
21
+ receive_request(%w[pending skipped], :update_total_coverage_status)
32
22
  end
33
23
 
34
24
  private
@@ -57,6 +47,22 @@ class CC::PullRequests < CC::Service
57
47
  raise NotImplementedError
58
48
  end
59
49
 
50
+ def update_diff_coverage_status_skipped
51
+ raise NotImplementedError
52
+ end
53
+
54
+ def update_diff_coverage_status_pending
55
+ raise NotImplementedError
56
+ end
57
+
58
+ def update_total_coverage_status_skipped
59
+ raise NotImplementedError
60
+ end
61
+
62
+ def update_total_coverage_status_pending
63
+ raise NotImplementedError
64
+ end
65
+
60
66
  def update_status_failure
61
67
  raise NotImplementedError
62
68
  end
@@ -91,6 +97,19 @@ class CC::PullRequests < CC::Service
91
97
  end
92
98
  end
93
99
 
100
+ def receive_request(*permitted_statuses, call_method)
101
+ setup_http
102
+ state = @payload["state"]
103
+
104
+ if permitted_statuses.flatten.include?(state) && report_status?
105
+ send(call_method.to_s + "_#{state}")
106
+ else
107
+ @response = simple_failure("Unknown state")
108
+ end
109
+
110
+ response
111
+ end
112
+
94
113
  def presenter
95
114
  CC::Service::PullRequestsPresenter.new(@payload)
96
115
  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,8 @@ module CC
36
36
  issue
37
37
  pull_request
38
38
  pull_request_coverage
39
+ pull_request_diff_coverage
40
+ pull_request_total_coverage
39
41
  quality
40
42
  snapshot
41
43
  test
@@ -71,6 +71,31 @@ 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
+
77
+ end
78
+
79
+ def update_total_coverage_status_skipped
80
+ update_status("success", presenter.skipped_message, "#{config.context}/total-coverage")
81
+ end
82
+
83
+ def update_diff_coverage_status_pending
84
+ update_status(
85
+ "pending",
86
+ @payload["message"] || presenter.pending_message,
87
+ "#{config.context}/diff-coverage"
88
+ )
89
+ end
90
+
91
+ def update_total_coverage_status_pending
92
+ update_status(
93
+ "pending",
94
+ @payload["message"] || presenter.pending_message,
95
+ "#{config.context}/total-coverage"
96
+ )
97
+ end
98
+
74
99
  def update_status_failure
75
100
  update_status("failure", presenter.success_message)
76
101
  end
@@ -1,5 +1,9 @@
1
1
  module CC
2
2
  module Services
3
- VERSION = "1.11.1".freeze
3
+ def version
4
+ path = File.expand_path("../../../../VERSION", __FILE__)
5
+ @version ||= File.read(path).strip
6
+ end
7
+ module_function :version
4
8
  end
5
9
  end
@@ -0,0 +1,131 @@
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
+
124
+ describe "#receive_pull_request_total_coverage" do
125
+ let(:payload_status) { "skipped" }
126
+ let(:expected_method_name) { :update_total_coverage_status_skipped }
127
+ let(:method_to_call) { :receive_pull_request_total_coverage }
128
+
129
+ it_behaves_like "receive method"
130
+ end
131
+ 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,48 @@ 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
+
89
+ receive_pull_request_diff_coverage({},
90
+ github_slug: "pbrisbin/foo",
91
+ commit_sha: "abc123",
92
+ state: "skipped")
93
+ end
94
+
95
+ it "pull request total coverage skipped" do
96
+ expect_status_update("pbrisbin/foo", "abc123", "state" => "success",
97
+ "description" => /skipped analysis/, "context" => /total-coverage/)
98
+
99
+ receive_pull_request_total_coverage({},
100
+ github_slug: "pbrisbin/foo",
101
+ commit_sha: "abc123",
102
+ state: "skipped")
103
+ end
104
+
105
+ it "pull request diff coverage pending" do
106
+ expect_status_update("pbrisbin/foo", "abc123", "state" => "pending",
107
+ "description" => /a test message/, "context" => /diff-coverage/)
108
+
109
+ receive_pull_request_diff_coverage({},
110
+ github_slug: "pbrisbin/foo",
111
+ commit_sha: "abc123",
112
+ state: "pending",
113
+ message: "a test message")
114
+ end
115
+
116
+ it "pull request total coverage skipped" do
117
+ expect_status_update("pbrisbin/foo", "abc123", "state" => "pending",
118
+ "description" => /a test message/, "context" => /total-coverage/)
119
+
120
+ receive_pull_request_total_coverage({},
121
+ github_slug: "pbrisbin/foo",
122
+ commit_sha: "abc123",
123
+ state: "pending",
124
+ message: "a test message")
125
+ end
126
+
85
127
  it "pull request status test success" do
86
128
  http_stubs.post("/repos/pbrisbin/foo/statuses/#{"0" * 40}") { |_env| [422, {}, ""] }
87
129
 
@@ -213,6 +255,22 @@ describe CC::Service::GitHubPullRequests, type: :service do
213
255
  )
214
256
  end
215
257
 
258
+ def receive_pull_request_diff_coverage(config, event_data)
259
+ service_receive(
260
+ CC::Service::GitHubPullRequests,
261
+ { oauth_token: "123" }.merge(config),
262
+ { name: "pull_request_diff_coverage" }.merge(event_data),
263
+ )
264
+ end
265
+
266
+ def receive_pull_request_total_coverage(config, event_data)
267
+ service_receive(
268
+ CC::Service::GitHubPullRequests,
269
+ { oauth_token: "123" }.merge(config),
270
+ { name: "pull_request_total_coverage" }.merge(event_data),
271
+ )
272
+ end
273
+
216
274
  def receive_test(config, event_data = {})
217
275
  service_receive(
218
276
  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.1
4
+ version: 1.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -130,6 +130,7 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".circleci/config.yml"
133
+ - ".circleci/shared.bash"
133
134
  - ".codeclimate.yml"
134
135
  - ".gitignore"
135
136
  - ".rspec"
@@ -139,6 +140,7 @@ files:
139
140
  - LICENSE.txt
140
141
  - README.md
141
142
  - Rakefile
143
+ - VERSION
142
144
  - base_rubocop.yml
143
145
  - bin/bundler
144
146
  - bin/coderay
@@ -194,10 +196,12 @@ files:
194
196
  - spec/axiom/types/token_spec.rb
195
197
  - spec/cc/formatters/snapshot_formatter_spec.rb
196
198
  - spec/cc/presenters/pull_requests_presenter_spec.rb
199
+ - spec/cc/pull_requests_spec.rb
197
200
  - spec/cc/resolve_spec.rb
198
201
  - spec/cc/service/asana_spec.rb
199
202
  - spec/cc/service/campfire_spec.rb
200
203
  - spec/cc/service/flowdock_spec.rb
204
+ - spec/cc/service/formatter_spec.rb
201
205
  - spec/cc/service/github_issues_spec.rb
202
206
  - spec/cc/service/github_pull_requests_spec.rb
203
207
  - spec/cc/service/gitlab_merge_requests_spec.rb
@@ -222,7 +226,7 @@ homepage: https://codeclimate.com/
222
226
  licenses:
223
227
  - MIT
224
228
  metadata: {}
225
- post_install_message:
229
+ post_install_message:
226
230
  rdoc_options: []
227
231
  require_paths:
228
232
  - lib
@@ -237,8 +241,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
241
  - !ruby/object:Gem::Version
238
242
  version: '0'
239
243
  requirements: []
240
- rubygems_version: 3.0.3
241
- signing_key:
244
+ rubygems_version: 3.3.7
245
+ signing_key:
242
246
  specification_version: 4
243
247
  summary: Service classes for Code Climate
244
248
  test_files:
@@ -246,10 +250,12 @@ test_files:
246
250
  - spec/axiom/types/token_spec.rb
247
251
  - spec/cc/formatters/snapshot_formatter_spec.rb
248
252
  - spec/cc/presenters/pull_requests_presenter_spec.rb
253
+ - spec/cc/pull_requests_spec.rb
249
254
  - spec/cc/resolve_spec.rb
250
255
  - spec/cc/service/asana_spec.rb
251
256
  - spec/cc/service/campfire_spec.rb
252
257
  - spec/cc/service/flowdock_spec.rb
258
+ - spec/cc/service/formatter_spec.rb
253
259
  - spec/cc/service/github_issues_spec.rb
254
260
  - spec/cc/service/github_pull_requests_spec.rb
255
261
  - spec/cc/service/gitlab_merge_requests_spec.rb