codecov 0.2.8 → 0.2.9

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 +31 -26
  3. data/test/test_codecov.rb +27 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e49b9d2e3374ac7e3f5d6514045a0454c767e200db364059887cb0d0a8a3e13f
4
- data.tar.gz: 83f5c298eb2be003da0302d329241f5eaa64a9d5d2d747be0b845437607bce88
3
+ metadata.gz: cdd8c92464da131becf5bae150b12f4ae3513d84c7f77ba059ee771ee662eca4
4
+ data.tar.gz: 592ed8f011c9e618aa2b71cf2c0ba7a9fb7a7ff1aa9ad80db72743f7f658cf24
5
5
  SHA512:
6
- metadata.gz: 4c8aba631f40e6fddca4d507613de63caf64207fda359518faceb9267e327cf0d4611ba864083e7ef8158fee9b8f4dfab10e8dfdd6e7f1f6e5d30ac4ae8275cb
7
- data.tar.gz: b15d9af39b437902e7f59a749bdf54dee8e12a97f4e78f8c4b918d001ca66606731a17986e4f52e0fe1e4a51b9c87ca652768395d60869da6cb5025cee876827
6
+ metadata.gz: ec4048e6ecb6c5780bfa1e4320a1edc177a5b96b6b2a3a7ba3a41416e5e1b40ea69e64d9cbeb58b920a566e9d3379244a4a21496500210adc9b51116325e5f0e
7
+ data.tar.gz: 4564c29b679ea650270560c719a1a178c8ab2d65fa9157e7892f06d02855b01ef5dcfe6be35e7cd47a836bec72abb74c1dc36002d9c030344549f987df9d930f
@@ -7,7 +7,7 @@ require 'simplecov'
7
7
  require 'zlib'
8
8
 
9
9
  class SimpleCov::Formatter::Codecov
10
- VERSION = '0.2.8'
10
+ VERSION = '0.2.9'
11
11
 
12
12
  ### CIs
13
13
  RECOGNIZED_CIS = [
@@ -17,6 +17,7 @@ class SimpleCov::Formatter::Codecov
17
17
  BITRISE = 'Bitrise CI',
18
18
  BUILDKITE = 'Buildkite CI',
19
19
  CIRCLE = 'Circle CI',
20
+ CODEBUILD = 'Codebuild CI',
20
21
  CODESHIP = 'Codeship CI',
21
22
  DRONEIO = 'Drone CI',
22
23
  GITHUB = 'GitHub Actions',
@@ -58,6 +59,8 @@ class SimpleCov::Formatter::Codecov
58
59
  BUILDKITE
59
60
  elsif (ENV['CI'] == 'true') && (ENV['CIRCLECI'] == 'true')
60
61
  CIRCLE
62
+ elsif ENV['CODEBUILD_CI'] == 'true'
63
+ CODEBUILD
61
64
  elsif (ENV['CI'] == 'true') && (ENV['CI_NAME'] == 'codeship')
62
65
  CODESHIP
63
66
  elsif ((ENV['CI'] == 'true') || (ENV['CI'] == 'drone')) && (ENV['DRONE'] == 'true')
@@ -85,7 +88,7 @@ class SimpleCov::Formatter::Codecov
85
88
  end
86
89
 
87
90
  if !RECOGNIZED_CIS.include?(ci)
88
- puts ['x>'.red, 'No CI provider detected.'].join(' ')
91
+ puts [red('x>'), 'No CI provider detected.'].join(' ')
89
92
  else
90
93
  puts "==> #{ci} detected"
91
94
  end
@@ -157,6 +160,15 @@ class SimpleCov::Formatter::Codecov
157
160
  params[:pr] = ENV['CIRCLE_PR_NUMBER']
158
161
  params[:branch] = ENV['CIRCLE_BRANCH']
159
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] = ENV['CODEBUILD_SOURCE_VERSION'].match(/pr\/(?<pr>.*)/)['pr'] if ENV['CODEBUILD_SOURCE_VERSION']
160
172
  when CODESHIP
161
173
  # https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
162
174
  params[:service] = 'codeship'
@@ -324,7 +336,7 @@ class SimpleCov::Formatter::Codecov
324
336
  end
325
337
 
326
338
  def gzip_report(report)
327
- puts ['==>'.green, 'Gzipping contents'].join(' ')
339
+ puts [green('==>'), 'Gzipping contents'].join(' ')
328
340
 
329
341
  io = StringIO.new
330
342
  gzip = Zlib::GzipWriter.new(io)
@@ -350,7 +362,7 @@ class SimpleCov::Formatter::Codecov
350
362
  report['params'] = params
351
363
  report['query'] = query
352
364
 
353
- puts ['==>'.green, 'Uploading reports'].join(' ')
365
+ puts [green('==>'), 'Uploading reports'].join(' ')
354
366
  puts " url: #{url}"
355
367
  puts " query: #{query_without_token}"
356
368
 
@@ -368,7 +380,7 @@ class SimpleCov::Formatter::Codecov
368
380
  https = Net::HTTP.new(uri.host, uri.port)
369
381
  https.use_ssl = !url.match(/^https/).nil?
370
382
 
371
- puts ['-> '.green, 'Pinging Codecov'].join(' ')
383
+ puts [green('-> '), 'Pinging Codecov'].join(' ')
372
384
  puts "#{url}#{uri.path}?#{query_without_token}"
373
385
 
374
386
  req = Net::HTTP::Post.new(
@@ -381,13 +393,13 @@ class SimpleCov::Formatter::Codecov
381
393
  )
382
394
  response = retry_request(req, https)
383
395
  if !response&.code || response.code == '400'
384
- puts response&.body&.red
396
+ puts red(response&.body)
385
397
  return false
386
398
  end
387
399
 
388
400
  reports_url = response.body.lines[0]
389
401
  s3target = response.body.lines[1]
390
- puts ['-> '.green, 'Uploading to'].join(' ')
402
+ puts [green('-> '), 'Uploading to'].join(' ')
391
403
  puts s3target
392
404
 
393
405
  uri = URI(s3target)
@@ -412,8 +424,8 @@ class SimpleCov::Formatter::Codecov
412
424
  'message' => 'Coverage reports upload successfully'
413
425
  }.to_json
414
426
  else
415
- puts ['-> '.black, 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
416
- puts res.body.red
427
+ puts [black('-> '), 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
428
+ puts red(res.body)
417
429
  nil
418
430
  end
419
431
  end
@@ -423,7 +435,7 @@ class SimpleCov::Formatter::Codecov
423
435
  https = Net::HTTP.new(uri.host, uri.port)
424
436
  https.use_ssl = !url.match(/^https/).nil?
425
437
 
426
- puts ['-> '.green, 'Uploading to Codecov'].join(' ')
438
+ puts [green('-> '), 'Uploading to Codecov'].join(' ')
427
439
  puts "#{url}#{uri.path}?#{query_without_token}"
428
440
 
429
441
  req = Net::HTTP::Post.new(
@@ -444,7 +456,7 @@ class SimpleCov::Formatter::Codecov
444
456
  if report['result']['uploaded']
445
457
  puts " View reports at #{report['result']['url']}"
446
458
  else
447
- puts ' X> Failed to upload coverage reports'.red
459
+ puts red(' X> Failed to upload coverage reports')
448
460
  end
449
461
  end
450
462
 
@@ -499,7 +511,7 @@ class SimpleCov::Formatter::Codecov
499
511
  'node_modules/'
500
512
  ]
501
513
 
502
- puts ['==>'.green, 'Appending file network'].join(' ')
514
+ puts [green('==>'), 'Appending file network'].join(' ')
503
515
  network = []
504
516
  Dir['**/*'].keep_if do |file|
505
517
  if File.file?(file) && !file.end_with?(*invalid_file_types) && !file.include?(*invalid_directories)
@@ -585,24 +597,17 @@ class SimpleCov::Formatter::Codecov
585
597
 
586
598
  true
587
599
  end
588
- end
589
-
590
- # https://stackoverflow.com/a/11482430/5769383
591
- class String
592
- # colorization
593
- def colorize(color_code)
594
- "\e[#{color_code}m#{self}\e[0m"
595
- end
596
600
 
597
- def black
598
- colorize(30)
601
+ # Convenience color methods
602
+ def black(str)
603
+ str.nil? ? '' : "\e[30m#{str}\e[0m"
599
604
  end
600
605
 
601
- def red
602
- colorize(31)
606
+ def red(str)
607
+ str.nil? ? '' : "\e[31m#{str}\e[0m"
603
608
  end
604
609
 
605
- def green
606
- colorize(32)
610
+ def green(str)
611
+ str.nil? ? '' : "\e[32m#{str}\e[0m"
607
612
  end
608
613
  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,27 @@ 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
+
615
642
  def test_filenames_are_shortened_correctly
616
643
  ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
617
644
 
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.8
4
+ version: 0.2.9
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-24 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json