codecov 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codecov.rb +9 -4
  3. data/test/test_codecov.rb +33 -2
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b2e67c7bb37041adf9adb9dbe2fd8f9c2966131d338961785a29b25090e7206
4
- data.tar.gz: 2ada93e046953b7e77397831259a21fcaef09012f4ea0c2c4584668b080d68a6
3
+ metadata.gz: 7cd3288a24f1d4655e837e068c45a5be7817d60c08de8acebb5ca0f3afcb0569
4
+ data.tar.gz: a42575d126b29448adda5177e95ac961070098aca3761c7074b4b6a1b9827154
5
5
  SHA512:
6
- metadata.gz: faf56288e9f75ee77f230da561da1ee87e3305fa7220e4b5962e2011e7f7d8c1f3c1a234a386ac698b00ad8999f500787f6b218c78c9009cb25bc096c056093c
7
- data.tar.gz: 233cbebb75102d82b62daf1087a490493ee3cef84de7e91163bc8c5040076f2f1798ebde32aa7971c2234c306adcc13c7a3abcc1929489c1aba124a319f195cb
6
+ metadata.gz: 00210aa6e8cbf2837c5c199e3f7b2ce3d80a7c171f4bb84f94c0202da55fff0b33fe7ea6ad2ec39ed65086d41b6c375433954197d0fd9343e4de0bc7cf437c83
7
+ data.tar.gz: e492d90061f8db4c1df141d5d2e04d520cf4f8704a923f5556ed5a50d28bc6fcf2ec9cf72acea749671da975cef11420a60d1c8bf20498291bb5761f79e3e35f
@@ -8,7 +8,7 @@ require 'colorize'
8
8
  require 'zlib'
9
9
 
10
10
  class SimpleCov::Formatter::Codecov
11
- VERSION = '0.2.6'
11
+ VERSION = '0.2.7'
12
12
 
13
13
  ### CIs
14
14
  RECOGNIZED_CIS = [
@@ -337,6 +337,7 @@ class SimpleCov::Formatter::Codecov
337
337
 
338
338
  def upload_to_codecov(ci, report)
339
339
  url = ENV['CODECOV_URL'] || 'https://codecov.io'
340
+ is_enterprise = url != 'https://codecov.io'
340
341
 
341
342
  params = build_params(ci)
342
343
  params_secret_token = params.clone
@@ -354,8 +355,11 @@ class SimpleCov::Formatter::Codecov
354
355
  puts " url: #{url}"
355
356
  puts " query: #{query_without_token}"
356
357
 
357
- response = upload_to_v4(url, gzipped_report, query, query_without_token)
358
- return false if response == false
358
+ response = false
359
+ unless is_enterprise
360
+ response = upload_to_v4(url, gzipped_report, query, query_without_token)
361
+ return false if response == false
362
+ end
359
363
 
360
364
  response || upload_to_v2(url, gzipped_report, query, query_without_token)
361
365
  end
@@ -421,11 +425,12 @@ class SimpleCov::Formatter::Codecov
421
425
  https.use_ssl = !url.match(/^https/).nil?
422
426
 
423
427
  puts ['-> '.green, 'Uploading to Codecov'].join(' ')
424
- puts "#{url}/#{uri.path}?#{query_without_token}"
428
+ puts "#{url}#{uri.path}?#{query_without_token}"
425
429
 
426
430
  req = Net::HTTP::Post.new(
427
431
  "#{uri.path}?#{query}",
428
432
  {
433
+ 'Accept' => 'application/json',
429
434
  'Content-Encoding' => 'gzip',
430
435
  'Content-Type' => 'text/plain',
431
436
  'X-Content-Encoding' => 'gzip'
@@ -6,7 +6,19 @@ class TestCodecov < Minitest::Test
6
6
  CI = SimpleCov::Formatter::Codecov.new.detect_ci
7
7
 
8
8
  REALENV =
9
- if CI == SimpleCov::Formatter::Codecov::GITHUB
9
+ if CI == SimpleCov::Formatter::Codecov::CIRCLE
10
+ {
11
+ 'CIRCLECI' => ENV['CIRCLECI'],
12
+ 'CIRCLE_BUILD_NUM' => ENV['CIRCLE_BUILD_NUM'],
13
+ 'CIRCLE_NODE_INDEX' => ENV['CIRCLE_NODE_INDEX'],
14
+ 'CIRCLE_PROJECT_REPONAME' => ENV['CIRCLE_PROJECT_REPONAME'],
15
+ 'CIRCLE_PROJECT_USERNAME' => ENV['CIRCLE_PROJECT_USERNAME'],
16
+ 'CIRCLE_REPOSITORY_URL' => ENV['CIRCLE_REPOSITORY_URL'],
17
+ 'CIRCLE_PR_NUMBER' => ENV['CIRCLE_PR_NUMBER'],
18
+ 'CIRCLE_BRANCH' => ENV['CIRCLE_BRANCH'],
19
+ 'CIRCLE_SHA1' => ENV['CIRCLE_SHA1']
20
+ }
21
+ elsif CI == SimpleCov::Formatter::Codecov::GITHUB
10
22
  {
11
23
  'GITHUB_ACTIONS' => ENV['GITHUB_ACTIONS'],
12
24
  'GITHUB_HEAD_REF' => ENV['GITHUB_HEAD_REF'],
@@ -51,6 +63,7 @@ class TestCodecov < Minitest::Test
51
63
  end
52
64
 
53
65
  def upload(success = true)
66
+ WebMock.enable!
54
67
  formatter = SimpleCov::Formatter::Codecov.new
55
68
  result = stub('SimpleCov::Result', files: [
56
69
  stub_file('/path/lib/something.rb', [1, 0, 0, nil, 1, nil]),
@@ -67,7 +80,7 @@ class TestCodecov < Minitest::Test
67
80
  end
68
81
 
69
82
  def success_stubs
70
- stub_request(:post, %r{https:\/\/codecov.io\/upload})
83
+ stub_request(:post, %r{https:\/\/codecov.io\/upload\/v4})
71
84
  .to_return(
72
85
  status: 200,
73
86
  body: "https://codecov.io/gh/fake\n" \
@@ -92,6 +105,7 @@ class TestCodecov < Minitest::Test
92
105
 
93
106
  def setup
94
107
  ENV['CI'] = nil
108
+ ENV['CIRCLECI'] = nil
95
109
  ENV['GITHUB_ACTIONS'] = nil
96
110
  ENV['TRAVIS'] = nil
97
111
  end
@@ -215,6 +229,23 @@ class TestCodecov < Minitest::Test
215
229
  assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
216
230
  end
217
231
 
232
+ def test_enterprise
233
+ stub = stub_request(:post, %r{https:\/\/example.com\/upload\/v2})
234
+ .to_return(
235
+ status: 200,
236
+ body: "{\"id\": \"12345678-1234-abcd-ef12-1234567890ab\", \"message\": \"Coverage reports upload successfully\", \"meta\": { \"status\": 200 }, \"queued\": true, \"uploaded\": true, \"url\": \"https://example.com/github/codecov/codecov-bash/commit/2f6b51562b93e72c610671644fe2a303c5c0e8e5\"}"
237
+ )
238
+
239
+ ENV['CODECOV_URL'] = 'https://example.com'
240
+ ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
241
+ result = upload
242
+ assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
243
+ assert_equal('12345678-1234-abcd-ef12-1234567890ab', result['result']['id'])
244
+ branch = `git rev-parse --abbrev-ref HEAD`.strip
245
+ assert_equal(branch != 'HEAD' ? branch : 'master', result['params'][:branch])
246
+ assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
247
+ end
248
+
218
249
  def test_travis
219
250
  ENV['CI'] = 'true'
220
251
  ENV['TRAVIS'] = 'true'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - codecov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-ci
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: mocha
71
85
  requirement: !ruby/object:Gem::Requirement