codecov 0.2.7 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codecov.rb +49 -16
  3. data/test/test_codecov.rb +48 -0
  4. metadata +6 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cd3288a24f1d4655e837e068c45a5be7817d60c08de8acebb5ca0f3afcb0569
4
- data.tar.gz: a42575d126b29448adda5177e95ac961070098aca3761c7074b4b6a1b9827154
3
+ metadata.gz: 98728653c21cce7decd7a9b031e54e950da789d70c464bb61e53e1964372ac1d
4
+ data.tar.gz: 8d45300d929ff5bd39cb5cfb562960ef1bf3b36b1f51754376f25c8ac8ae3a31
5
5
  SHA512:
6
- metadata.gz: 00210aa6e8cbf2837c5c199e3f7b2ce3d80a7c171f4bb84f94c0202da55fff0b33fe7ea6ad2ec39ed65086d41b6c375433954197d0fd9343e4de0bc7cf437c83
7
- data.tar.gz: e492d90061f8db4c1df141d5d2e04d520cf4f8704a923f5556ed5a50d28bc6fcf2ec9cf72acea749671da975cef11420a60d1c8bf20498291bb5761f79e3e35f
6
+ metadata.gz: bdd1f35739f17cc5110ea0c2fa51bf4939812b96ff96009311dfb52ea67b63107cdbfbb8ad6e9b76f1cdc1104a136407bf1f9e89d1509c717131d9b03e62a986
7
+ data.tar.gz: 84673f1a411a1b7746b04448a79aa9a84b3e5606d14f7c70b6adee66be765f66ba2caed073cda2dc837788b7a67cc3a0c6c232655533e1170ea0865b30f77c93
@@ -4,11 +4,10 @@ require 'uri'
4
4
  require 'json'
5
5
  require 'net/http'
6
6
  require 'simplecov'
7
- require 'colorize'
8
7
  require 'zlib'
9
8
 
10
9
  class SimpleCov::Formatter::Codecov
11
- VERSION = '0.2.7'
10
+ VERSION = '0.2.12'
12
11
 
13
12
  ### CIs
14
13
  RECOGNIZED_CIS = [
@@ -18,6 +17,7 @@ class SimpleCov::Formatter::Codecov
18
17
  BITRISE = 'Bitrise CI',
19
18
  BUILDKITE = 'Buildkite CI',
20
19
  CIRCLE = 'Circle CI',
20
+ CODEBUILD = 'Codebuild CI',
21
21
  CODESHIP = 'Codeship CI',
22
22
  DRONEIO = 'Drone CI',
23
23
  GITHUB = 'GitHub Actions',
@@ -59,6 +59,8 @@ class SimpleCov::Formatter::Codecov
59
59
  BUILDKITE
60
60
  elsif (ENV['CI'] == 'true') && (ENV['CIRCLECI'] == 'true')
61
61
  CIRCLE
62
+ elsif ENV['CODEBUILD_CI'] == 'true'
63
+ CODEBUILD
62
64
  elsif (ENV['CI'] == 'true') && (ENV['CI_NAME'] == 'codeship')
63
65
  CODESHIP
64
66
  elsif ((ENV['CI'] == 'true') || (ENV['CI'] == 'drone')) && (ENV['DRONE'] == 'true')
@@ -86,7 +88,7 @@ class SimpleCov::Formatter::Codecov
86
88
  end
87
89
 
88
90
  if !RECOGNIZED_CIS.include?(ci)
89
- puts ['x>'.red, 'No CI provider detected.'].join(' ')
91
+ puts [red('x>'), 'No CI provider detected.'].join(' ')
90
92
  else
91
93
  puts "==> #{ci} detected"
92
94
  end
@@ -158,6 +160,18 @@ class SimpleCov::Formatter::Codecov
158
160
  params[:pr] = ENV['CIRCLE_PR_NUMBER']
159
161
  params[:branch] = ENV['CIRCLE_BRANCH']
160
162
  params[:commit] = ENV['CIRCLE_SHA1']
163
+ when CODEBUILD
164
+ # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
165
+ params[:service] = 'codebuild'
166
+ params[:branch] = ENV['CODEBUILD_WEBHOOK_HEAD_REF'].split('/')[2]
167
+ params[:build] = ENV['CODEBUILD_BUILD_ID']
168
+ params[:commit] = ENV['CODEBUILD_RESOLVED_SOURCE_VERSION']
169
+ params[:job] = ENV['CODEBUILD_BUILD_ID']
170
+ params[:slug] = ENV['CODEBUILD_SOURCE_REPO_URL'].match(/.*github.com\/(?<slug>.*).git/)['slug']
171
+ params[:pr] = if ENV['CODEBUILD_SOURCE_VERSION']
172
+ matched = ENV['CODEBUILD_SOURCE_VERSION'].match(%r{pr/(?<pr>.*)})
173
+ matched.nil? ? ENV['CODEBUILD_SOURCE_VERSION'] : matched['pr']
174
+ end
161
175
  when CODESHIP
162
176
  # https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
163
177
  params[:service] = 'codeship'
@@ -308,6 +322,7 @@ class SimpleCov::Formatter::Codecov
308
322
  puts 'Error uploading coverage reports to Codecov. Sorry'
309
323
  puts e.class.name
310
324
  puts e
325
+ puts "Backtrace:\n\t#{e.backtrace}"
311
326
  return response
312
327
  end
313
328
 
@@ -325,7 +340,7 @@ class SimpleCov::Formatter::Codecov
325
340
  end
326
341
 
327
342
  def gzip_report(report)
328
- puts ['==>'.green, 'Gzipping contents'].join(' ')
343
+ puts [green('==>'), 'Gzipping contents'].join(' ')
329
344
 
330
345
  io = StringIO.new
331
346
  gzip = Zlib::GzipWriter.new(io)
@@ -351,7 +366,7 @@ class SimpleCov::Formatter::Codecov
351
366
  report['params'] = params
352
367
  report['query'] = query
353
368
 
354
- puts ['==>'.green, 'Uploading reports'].join(' ')
369
+ puts [green('==>'), 'Uploading reports'].join(' ')
355
370
  puts " url: #{url}"
356
371
  puts " query: #{query_without_token}"
357
372
 
@@ -369,7 +384,7 @@ class SimpleCov::Formatter::Codecov
369
384
  https = Net::HTTP.new(uri.host, uri.port)
370
385
  https.use_ssl = !url.match(/^https/).nil?
371
386
 
372
- puts ['-> '.green, 'Pinging Codecov'].join(' ')
387
+ puts [green('-> '), 'Pinging Codecov'].join(' ')
373
388
  puts "#{url}#{uri.path}?#{query_without_token}"
374
389
 
375
390
  req = Net::HTTP::Post.new(
@@ -382,13 +397,13 @@ class SimpleCov::Formatter::Codecov
382
397
  )
383
398
  response = retry_request(req, https)
384
399
  if !response&.code || response.code == '400'
385
- puts response&.body&.red
400
+ puts red(response&.body)
386
401
  return false
387
402
  end
388
403
 
389
404
  reports_url = response.body.lines[0]
390
405
  s3target = response.body.lines[1]
391
- puts ['-> '.green, 'Uploading to'].join(' ')
406
+ puts [green('-> '), 'Uploading to'].join(' ')
392
407
  puts s3target
393
408
 
394
409
  uri = URI(s3target)
@@ -403,7 +418,7 @@ class SimpleCov::Formatter::Codecov
403
418
  )
404
419
  req.body = report
405
420
  res = retry_request(req, https)
406
- if res.body == ''
421
+ if res&.body == ''
407
422
  {
408
423
  'uploaded' => true,
409
424
  'url' => reports_url,
@@ -413,8 +428,8 @@ class SimpleCov::Formatter::Codecov
413
428
  'message' => 'Coverage reports upload successfully'
414
429
  }.to_json
415
430
  else
416
- puts ['-> '.black, 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
417
- puts res.body.red
431
+ puts [black('-> '), 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
432
+ puts red(res&.body || 'nil')
418
433
  nil
419
434
  end
420
435
  end
@@ -424,7 +439,7 @@ class SimpleCov::Formatter::Codecov
424
439
  https = Net::HTTP.new(uri.host, uri.port)
425
440
  https.use_ssl = !url.match(/^https/).nil?
426
441
 
427
- puts ['-> '.green, 'Uploading to Codecov'].join(' ')
442
+ puts [green('-> '), 'Uploading to Codecov'].join(' ')
428
443
  puts "#{url}#{uri.path}?#{query_without_token}"
429
444
 
430
445
  req = Net::HTTP::Post.new(
@@ -445,7 +460,7 @@ class SimpleCov::Formatter::Codecov
445
460
  if report['result']['uploaded']
446
461
  puts " View reports at #{report['result']['url']}"
447
462
  else
448
- puts ' X> Failed to upload coverage reports'.red
463
+ puts red(' X> Failed to upload coverage reports')
449
464
  end
450
465
  end
451
466
 
@@ -497,16 +512,21 @@ class SimpleCov::Formatter::Codecov
497
512
  ].freeze
498
513
 
499
514
  invalid_directories = [
500
- 'node_modules/'
515
+ 'node_modules/',
516
+ 'public/',
517
+ 'storage/',
518
+ 'tmp/',
519
+ 'vendor/'
501
520
  ]
502
521
 
503
- puts ['==>'.green, 'Appending file network'].join(' ')
522
+ puts [green('==>'), 'Appending file network'].join(' ')
504
523
  network = []
505
524
  Dir['**/*'].keep_if do |file|
506
- if File.file?(file) && !file.end_with?(*invalid_file_types) && !file.include?(*invalid_directories)
525
+ if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) }
507
526
  network.push(file)
508
527
  end
509
528
  end
529
+
510
530
  network.push('<<<<<< network')
511
531
  network
512
532
  end
@@ -586,4 +606,17 @@ class SimpleCov::Formatter::Codecov
586
606
 
587
607
  true
588
608
  end
609
+
610
+ # Convenience color methods
611
+ def black(str)
612
+ str.nil? ? '' : "\e[30m#{str}\e[0m"
613
+ end
614
+
615
+ def red(str)
616
+ str.nil? ? '' : "\e[31m#{str}\e[0m"
617
+ end
618
+
619
+ def green(str)
620
+ str.nil? ? '' : "\e[32m#{str}\e[0m"
621
+ end
589
622
  end
@@ -167,6 +167,12 @@ class TestCodecov < Minitest::Test
167
167
  ENV['CIRCLE_PROJECT_USERNAME'] = nil
168
168
  ENV['CIRCLE_SHA1'] = nil
169
169
  ENV['CIRCLECI'] = nil
170
+ ENV['CODEBUILD_CI'] = nil
171
+ ENV['CODEBUILD_BUILD_ID'] = nil
172
+ ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'] = nil
173
+ ENV['CODEBUILD_WEBHOOK_HEAD_REF'] = nil
174
+ ENV['CODEBUILD_SOURCE_VERSION'] = nil
175
+ ENV['CODEBUILD_SOURCE_REPO_URL'] = nil
170
176
  ENV['CODECOV_ENV'] = nil
171
177
  ENV['CODECOV_SLUG'] = nil
172
178
  ENV['CODECOV_TOKEN'] = nil
@@ -612,6 +618,48 @@ class TestCodecov < Minitest::Test
612
618
  assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
613
619
  end
614
620
 
621
+ def test_codebuild
622
+ ENV['CODEBUILD_CI'] = "true"
623
+ ENV['CODEBUILD_BUILD_ID'] = "codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3"
624
+ ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'] = 'd653b934ed59c1a785cc1cc79d08c9aaa4eba73b'
625
+ ENV['CODEBUILD_WEBHOOK_HEAD_REF'] = 'refs/heads/master'
626
+ ENV['CODEBUILD_SOURCE_VERSION'] = 'pr/123'
627
+ ENV['CODEBUILD_SOURCE_REPO_URL'] = 'https://github.com/owner/repo.git'
628
+ ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
629
+
630
+ result = upload
631
+
632
+ assert_equal("codebuild", result['params'][:service])
633
+ assert_equal("d653b934ed59c1a785cc1cc79d08c9aaa4eba73b", result['params'][:commit])
634
+ assert_equal("codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3", result['params'][:build])
635
+ assert_equal("codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3", result['params'][:job])
636
+ assert_equal("owner/repo", result['params'][:slug])
637
+ assert_equal("master", result['params'][:branch])
638
+ assert_equal("123", result['params'][:pr])
639
+ assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
640
+ end
641
+
642
+ def test_codebuild_source_version_is_other_than_pr_number
643
+ ENV['CODEBUILD_CI'] = 'true'
644
+ ENV['CODEBUILD_BUILD_ID'] = 'codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3'
645
+ ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'] = 'd653b934ed59c1a785cc1cc79d08c9aaa4eba73b'
646
+ ENV['CODEBUILD_WEBHOOK_HEAD_REF'] = 'refs/heads/master'
647
+ ENV['CODEBUILD_SOURCE_VERSION'] = 'git-commit-hash-12345'
648
+ ENV['CODEBUILD_SOURCE_REPO_URL'] = 'https://github.com/owner/repo.git'
649
+ ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
650
+
651
+ result = upload
652
+
653
+ assert_equal('codebuild', result['params'][:service])
654
+ assert_equal('d653b934ed59c1a785cc1cc79d08c9aaa4eba73b', result['params'][:commit])
655
+ assert_equal('codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3', result['params'][:build])
656
+ assert_equal('git-commit-hash-12345', result['params'][:pr])
657
+ assert_equal('owner/repo', result['params'][:slug])
658
+ assert_equal('master', result['params'][:branch])
659
+ assert_equal('git-commit-hash-12345', result['params'][:pr])
660
+ assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
661
+ end
662
+
615
663
  def test_filenames_are_shortened_correctly
616
664
  ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
617
665
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - codecov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: colorize
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: json
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +135,7 @@ homepage: https://github.com/codecov/codecov-ruby
149
135
  licenses:
150
136
  - MIT
151
137
  metadata: {}
152
- post_install_message:
138
+ post_install_message:
153
139
  rdoc_options: []
154
140
  require_paths:
155
141
  - lib
@@ -164,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
150
  - !ruby/object:Gem::Version
165
151
  version: '0'
166
152
  requirements: []
167
- rubygems_version: 3.1.2
168
- signing_key:
153
+ rubygems_version: 3.0.3
154
+ signing_key:
169
155
  specification_version: 4
170
156
  summary: hosted code coverage ruby/rails reporter
171
157
  test_files: