codecov 0.2.8 → 0.2.13

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 +50 -32
  3. metadata +40 -55
  4. data/test/test_codecov.rb +0 -648
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e49b9d2e3374ac7e3f5d6514045a0454c767e200db364059887cb0d0a8a3e13f
4
- data.tar.gz: 83f5c298eb2be003da0302d329241f5eaa64a9d5d2d747be0b845437607bce88
3
+ metadata.gz: 75ab24dda77623328bb256121c146e749bf1e603d11cf9e09fd221a53e2de72c
4
+ data.tar.gz: 58a176feaa17140c94356f46d6cba02c1aea7a581ce4f870fe707569bb769793
5
5
  SHA512:
6
- metadata.gz: 4c8aba631f40e6fddca4d507613de63caf64207fda359518faceb9267e327cf0d4611ba864083e7ef8158fee9b8f4dfab10e8dfdd6e7f1f6e5d30ac4ae8275cb
7
- data.tar.gz: b15d9af39b437902e7f59a749bdf54dee8e12a97f4e78f8c4b918d001ca66606731a17986e4f52e0fe1e4a51b9c87ca652768395d60869da6cb5025cee876827
6
+ metadata.gz: a47d3113eef1bee9492dcf8b6513f1be2aaa9d397167153bd6f2903786c7d60de82325475c1ff94acb152cae8619720edc0aee6f5280632dbd44621e040a2385
7
+ data.tar.gz: 7949c0bce5c9fd2caf25547fdb4c431e63eb495848534e993ceac98b649b35713e8b4764822e8d99147e9a0e8da1d3356c8323ed5a17dff73f709ca03aa22f90
@@ -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.13'
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,18 @@ 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] = 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
160
175
  when CODESHIP
161
176
  # https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
162
177
  params[:service] = 'codeship'
@@ -177,9 +192,13 @@ class SimpleCov::Formatter::Codecov
177
192
  when GITHUB
178
193
  # https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
179
194
  params[:service] = 'github-actions'
180
- params[:branch] = ENV['GITHUB_HEAD_REF'] || ENV['GITHUB_REF'].sub('refs/head/', '')
181
- # PR refs are in the format: refs/pull/7/merge for pull_request events
182
- params[:pr] = ENV['GITHUB_REF'].split('/')[2] unless ENV['GITHUB_HEAD_REF'].nil? || ENV['GITHUB_HEAD_REF'].empty?
195
+ if (ENV['GITHUB_HEAD_REF'] || '').empty?
196
+ params[:branch] = ENV['GITHUB_REF'].sub('refs/heads/', '')
197
+ else
198
+ params[:branch] = ENV['GITHUB_HEAD_REF']
199
+ # PR refs are in the format: refs/pull/7/merge for pull_request events
200
+ params[:pr] = ENV['GITHUB_REF'].split('/')[2]
201
+ end
183
202
  params[:slug] = ENV['GITHUB_REPOSITORY']
184
203
  params[:build] = ENV['GITHUB_RUN_ID']
185
204
  params[:commit] = ENV['GITHUB_SHA']
@@ -307,6 +326,7 @@ class SimpleCov::Formatter::Codecov
307
326
  puts 'Error uploading coverage reports to Codecov. Sorry'
308
327
  puts e.class.name
309
328
  puts e
329
+ puts "Backtrace:\n\t#{e.backtrace}"
310
330
  return response
311
331
  end
312
332
 
@@ -324,7 +344,7 @@ class SimpleCov::Formatter::Codecov
324
344
  end
325
345
 
326
346
  def gzip_report(report)
327
- puts ['==>'.green, 'Gzipping contents'].join(' ')
347
+ puts [green('==>'), 'Gzipping contents'].join(' ')
328
348
 
329
349
  io = StringIO.new
330
350
  gzip = Zlib::GzipWriter.new(io)
@@ -350,7 +370,7 @@ class SimpleCov::Formatter::Codecov
350
370
  report['params'] = params
351
371
  report['query'] = query
352
372
 
353
- puts ['==>'.green, 'Uploading reports'].join(' ')
373
+ puts [green('==>'), 'Uploading reports'].join(' ')
354
374
  puts " url: #{url}"
355
375
  puts " query: #{query_without_token}"
356
376
 
@@ -368,7 +388,7 @@ class SimpleCov::Formatter::Codecov
368
388
  https = Net::HTTP.new(uri.host, uri.port)
369
389
  https.use_ssl = !url.match(/^https/).nil?
370
390
 
371
- puts ['-> '.green, 'Pinging Codecov'].join(' ')
391
+ puts [green('-> '), 'Pinging Codecov'].join(' ')
372
392
  puts "#{url}#{uri.path}?#{query_without_token}"
373
393
 
374
394
  req = Net::HTTP::Post.new(
@@ -381,13 +401,13 @@ class SimpleCov::Formatter::Codecov
381
401
  )
382
402
  response = retry_request(req, https)
383
403
  if !response&.code || response.code == '400'
384
- puts response&.body&.red
404
+ puts red(response&.body)
385
405
  return false
386
406
  end
387
407
 
388
408
  reports_url = response.body.lines[0]
389
409
  s3target = response.body.lines[1]
390
- puts ['-> '.green, 'Uploading to'].join(' ')
410
+ puts [green('-> '), 'Uploading to'].join(' ')
391
411
  puts s3target
392
412
 
393
413
  uri = URI(s3target)
@@ -402,7 +422,7 @@ class SimpleCov::Formatter::Codecov
402
422
  )
403
423
  req.body = report
404
424
  res = retry_request(req, https)
405
- if res.body == ''
425
+ if res&.body == ''
406
426
  {
407
427
  'uploaded' => true,
408
428
  'url' => reports_url,
@@ -412,8 +432,8 @@ class SimpleCov::Formatter::Codecov
412
432
  'message' => 'Coverage reports upload successfully'
413
433
  }.to_json
414
434
  else
415
- puts ['-> '.black, 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
416
- puts res.body.red
435
+ puts [black('-> '), 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
436
+ puts red(res&.body || 'nil')
417
437
  nil
418
438
  end
419
439
  end
@@ -423,7 +443,7 @@ class SimpleCov::Formatter::Codecov
423
443
  https = Net::HTTP.new(uri.host, uri.port)
424
444
  https.use_ssl = !url.match(/^https/).nil?
425
445
 
426
- puts ['-> '.green, 'Uploading to Codecov'].join(' ')
446
+ puts [green('-> '), 'Uploading to Codecov'].join(' ')
427
447
  puts "#{url}#{uri.path}?#{query_without_token}"
428
448
 
429
449
  req = Net::HTTP::Post.new(
@@ -444,7 +464,7 @@ class SimpleCov::Formatter::Codecov
444
464
  if report['result']['uploaded']
445
465
  puts " View reports at #{report['result']['url']}"
446
466
  else
447
- puts ' X> Failed to upload coverage reports'.red
467
+ puts red(' X> Failed to upload coverage reports')
448
468
  end
449
469
  end
450
470
 
@@ -496,16 +516,21 @@ class SimpleCov::Formatter::Codecov
496
516
  ].freeze
497
517
 
498
518
  invalid_directories = [
499
- 'node_modules/'
519
+ 'node_modules/',
520
+ 'public/',
521
+ 'storage/',
522
+ 'tmp/',
523
+ 'vendor/'
500
524
  ]
501
525
 
502
- puts ['==>'.green, 'Appending file network'].join(' ')
526
+ puts [green('==>'), 'Appending file network'].join(' ')
503
527
  network = []
504
528
  Dir['**/*'].keep_if do |file|
505
- if File.file?(file) && !file.end_with?(*invalid_file_types) && !file.include?(*invalid_directories)
529
+ if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) }
506
530
  network.push(file)
507
531
  end
508
532
  end
533
+
509
534
  network.push('<<<<<< network')
510
535
  network
511
536
  end
@@ -585,24 +610,17 @@ class SimpleCov::Formatter::Codecov
585
610
 
586
611
  true
587
612
  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
613
 
597
- def black
598
- colorize(30)
614
+ # Convenience color methods
615
+ def black(str)
616
+ str.nil? ? '' : "\e[30m#{str}\e[0m"
599
617
  end
600
618
 
601
- def red
602
- colorize(31)
619
+ def red(str)
620
+ str.nil? ? '' : "\e[31m#{str}\e[0m"
603
621
  end
604
622
 
605
- def green
606
- colorize(32)
623
+ def green(str)
624
+ str.nil? ? '' : "\e[32m#{str}\e[0m"
607
625
  end
608
626
  end
metadata CHANGED
@@ -1,128 +1,115 @@
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.13
5
5
  platform: ruby
6
6
  authors:
7
- - codecov
8
- autorequire:
7
+ - Steve Peak
8
+ - Tom Hu
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-08-24 00:00:00.000000000 Z
12
+ date: 2020-12-10 00:00:00.000000000 Z
12
13
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json
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
14
  - !ruby/object:Gem::Dependency
28
15
  name: simplecov
29
16
  requirement: !ruby/object:Gem::Requirement
30
17
  requirements:
31
- - - ">="
18
+ - - "~>"
32
19
  - !ruby/object:Gem::Version
33
- version: '0'
20
+ version: 0.18.0
34
21
  type: :runtime
35
22
  prerelease: false
36
23
  version_requirements: !ruby/object:Gem::Requirement
37
24
  requirements:
38
- - - ">="
25
+ - - "~>"
39
26
  - !ruby/object:Gem::Version
40
- version: '0'
27
+ version: 0.18.0
41
28
  - !ruby/object:Gem::Dependency
42
29
  name: minitest
43
30
  requirement: !ruby/object:Gem::Requirement
44
31
  requirements:
45
- - - ">="
32
+ - - "~>"
46
33
  - !ruby/object:Gem::Version
47
- version: '0'
34
+ version: '5.0'
48
35
  type: :development
49
36
  prerelease: false
50
37
  version_requirements: !ruby/object:Gem::Requirement
51
38
  requirements:
52
- - - ">="
39
+ - - "~>"
53
40
  - !ruby/object:Gem::Version
54
- version: '0'
41
+ version: '5.0'
55
42
  - !ruby/object:Gem::Dependency
56
43
  name: minitest-ci
57
44
  requirement: !ruby/object:Gem::Requirement
58
45
  requirements:
59
- - - ">="
46
+ - - "~>"
60
47
  - !ruby/object:Gem::Version
61
- version: '0'
48
+ version: '3.0'
62
49
  type: :development
63
50
  prerelease: false
64
51
  version_requirements: !ruby/object:Gem::Requirement
65
52
  requirements:
66
- - - ">="
53
+ - - "~>"
67
54
  - !ruby/object:Gem::Version
68
- version: '0'
55
+ version: '3.0'
69
56
  - !ruby/object:Gem::Dependency
70
57
  name: mocha
71
58
  requirement: !ruby/object:Gem::Requirement
72
59
  requirements:
73
- - - ">="
60
+ - - "~>"
74
61
  - !ruby/object:Gem::Version
75
- version: '0'
62
+ version: '1.0'
76
63
  type: :development
77
64
  prerelease: false
78
65
  version_requirements: !ruby/object:Gem::Requirement
79
66
  requirements:
80
- - - ">="
67
+ - - "~>"
81
68
  - !ruby/object:Gem::Version
82
- version: '0'
69
+ version: '1.0'
83
70
  - !ruby/object:Gem::Dependency
84
71
  name: rake
85
72
  requirement: !ruby/object:Gem::Requirement
86
73
  requirements:
87
- - - ">="
74
+ - - "~>"
88
75
  - !ruby/object:Gem::Version
89
- version: '0'
76
+ version: '13.0'
90
77
  type: :development
91
78
  prerelease: false
92
79
  version_requirements: !ruby/object:Gem::Requirement
93
80
  requirements:
94
- - - ">="
81
+ - - "~>"
95
82
  - !ruby/object:Gem::Version
96
- version: '0'
83
+ version: '13.0'
97
84
  - !ruby/object:Gem::Dependency
98
85
  name: rubocop
99
86
  requirement: !ruby/object:Gem::Requirement
100
87
  requirements:
101
- - - ">="
88
+ - - "~>"
102
89
  - !ruby/object:Gem::Version
103
- version: '0'
90
+ version: '1.0'
104
91
  type: :development
105
92
  prerelease: false
106
93
  version_requirements: !ruby/object:Gem::Requirement
107
94
  requirements:
108
- - - ">="
95
+ - - "~>"
109
96
  - !ruby/object:Gem::Version
110
- version: '0'
97
+ version: '1.0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: webmock
113
100
  requirement: !ruby/object:Gem::Requirement
114
101
  requirements:
115
- - - ">="
102
+ - - "~>"
116
103
  - !ruby/object:Gem::Version
117
- version: '0'
104
+ version: '3.0'
118
105
  type: :development
119
106
  prerelease: false
120
107
  version_requirements: !ruby/object:Gem::Requirement
121
108
  requirements:
122
- - - ">="
109
+ - - "~>"
123
110
  - !ruby/object:Gem::Version
124
- version: '0'
125
- description: hosted code coverage
111
+ version: '3.0'
112
+ description: Hosted code coverage Ruby reporter.
126
113
  email:
127
114
  - hello@codecov.io
128
115
  executables: []
@@ -130,18 +117,17 @@ extensions: []
130
117
  extra_rdoc_files: []
131
118
  files:
132
119
  - lib/codecov.rb
133
- - test/test_codecov.rb
134
120
  homepage: https://github.com/codecov/codecov-ruby
135
121
  licenses:
136
122
  - MIT
137
123
  metadata: {}
138
- post_install_message:
124
+ post_install_message:
139
125
  rdoc_options: []
140
126
  require_paths:
141
127
  - lib
142
128
  required_ruby_version: !ruby/object:Gem::Requirement
143
129
  requirements:
144
- - - ">="
130
+ - - "~>"
145
131
  - !ruby/object:Gem::Version
146
132
  version: '2.4'
147
133
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -150,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
136
  - !ruby/object:Gem::Version
151
137
  version: '0'
152
138
  requirements: []
153
- rubygems_version: 3.1.2
154
- signing_key:
139
+ rubygems_version: 3.0.3
140
+ signing_key:
155
141
  specification_version: 4
156
- summary: hosted code coverage ruby/rails reporter
157
- test_files:
158
- - test/test_codecov.rb
142
+ summary: Hosted code coverage
143
+ test_files: []
@@ -1,648 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TestCodecov < Minitest::Test
6
- CI = SimpleCov::Formatter::Codecov.new.detect_ci
7
-
8
- REALENV =
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
22
- {
23
- 'GITHUB_ACTIONS' => ENV['GITHUB_ACTIONS'],
24
- 'GITHUB_HEAD_REF' => ENV['GITHUB_HEAD_REF'],
25
- 'GITHUB_REF' => ENV['GITHUB_REF'],
26
- 'GITHUB_REPOSITORY' => ENV['GITHUB_REPOSITORY'],
27
- 'GITHUB_RUN_ID' => ENV['GITHUB_RUN_ID'],
28
- 'GITHUB_SHA' => ENV['GITHUB_SHA']
29
- }
30
- elsif CI == SimpleCov::Formatter::Codecov::TRAVIS
31
- {
32
- 'TRAVIS' => ENV['TRAVIS'],
33
- 'TRAVIS_BRANCH' => ENV['TRAVIS_BRANCH'],
34
- 'TRAVIS_COMMIT' => ENV['TRAVIS_COMMIT'],
35
- 'TRAVIS_REPO_SLUG' => ENV['TRAVIS_REPO_SLUG'],
36
- 'TRAVIS_JOB_NUMBER' => ENV['TRAVIS_JOB_NUMBER'],
37
- 'TRAVIS_PULL_REQUEST' => ENV['TRAVIS_PULL_REQUEST'],
38
- 'TRAVIS_JOB_ID' => ENV['TRAVIS_JOB_ID']
39
- }
40
- else
41
- {}
42
- end.freeze
43
-
44
- def url
45
- ENV['CODECOV_URL'] || 'https://codecov.io'
46
- end
47
-
48
- def test_defined
49
- assert defined?(SimpleCov::Formatter::Codecov)
50
- assert defined?(SimpleCov::Formatter::Codecov::VERSION)
51
- end
52
-
53
- def stub_file(filename, coverage)
54
- lines = coverage.each_with_index.map do |cov, i|
55
- skipped = false
56
- if cov == :skipped
57
- skipped = true
58
- cov = 0
59
- end
60
- stub('SimpleCov::SourceFile::Line', skipped?: skipped, line_number: i + 1, coverage: cov)
61
- end
62
- stub('SimpleCov::SourceFile', filename: filename, lines: lines)
63
- end
64
-
65
- def upload(success = true)
66
- WebMock.enable!
67
- formatter = SimpleCov::Formatter::Codecov.new
68
- result = stub('SimpleCov::Result', files: [
69
- stub_file('/path/lib/something.rb', [1, 0, 0, nil, 1, nil]),
70
- stub_file('/path/lib/somefile.rb', [1, nil, 1, 1, 1, 0, 0, nil, 1, nil])
71
- ])
72
- SimpleCov.stubs(:root).returns('/path')
73
- success_stubs if success
74
- data = formatter.format(result, false)
75
- puts data
76
- puts data['params']
77
- assert_successful_upload(data) if success
78
- WebMock.reset!
79
- data
80
- end
81
-
82
- def success_stubs
83
- stub_request(:post, %r{https:\/\/codecov.io\/upload\/v4})
84
- .to_return(
85
- status: 200,
86
- body: "https://codecov.io/gh/fake\n" \
87
- 'https://storage.googleapis.com/codecov/fake'
88
- )
89
- stub_request(:put, %r{https:\/\/storage.googleapis.com\/})
90
- .to_return(
91
- status: 200,
92
- body: ''
93
- )
94
- end
95
-
96
- def assert_successful_upload(data)
97
- assert_equal(data['result']['uploaded'], true)
98
- assert_equal(data['result']['message'], 'Coverage reports upload successfully')
99
- assert_equal(data['meta']['version'], 'codecov-ruby/v' + SimpleCov::Formatter::Codecov::VERSION)
100
- assert_equal(data['coverage'].to_json, {
101
- 'lib/something.rb' => [nil, 1, 0, 0, nil, 1, nil],
102
- 'lib/somefile.rb' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil]
103
- }.to_json)
104
- end
105
-
106
- def setup
107
- ENV['CI'] = nil
108
- ENV['CIRCLECI'] = nil
109
- ENV['GITHUB_ACTIONS'] = nil
110
- ENV['TRAVIS'] = nil
111
- end
112
-
113
- def teardown
114
- # needed for sending this projects coverage
115
- ENV['APPVEYOR'] = nil
116
- ENV['APPVEYOR_ACCOUNT_NAME'] = nil
117
- ENV['APPVEYOR_BUILD_VERSION'] = nil
118
- ENV['APPVEYOR_JOB_ID'] = nil
119
- ENV['APPVEYOR_PROJECT_SLUG'] = nil
120
- ENV['APPVEYOR_PULL_REQUEST_NUMBER'] = nil
121
- ENV['APPVEYOR_REPO_BRANCH'] = nil
122
- ENV['APPVEYOR_REPO_COMMIT'] = nil
123
- ENV['APPVEYOR_REPO_NAME'] = nil
124
- ENV['BITBUCKET_BRANCH'] = nil
125
- ENV['BITBUCKET_BUILD_NUMBER'] = nil
126
- ENV['BITBUCKET_COMMIT'] = nil
127
- ENV['BITRISE_BUILD_NUMBER'] = nil
128
- ENV['BITRISE_BUILD_URL'] = nil
129
- ENV['BITRISE_GIT_BRANCH'] = nil
130
- ENV['BITRISE_GIT_COMMIT'] = nil
131
- ENV['BITRISE_IO'] = nil
132
- ENV['BITRISE_PULL_REQUEST'] = nil
133
- ENV['BITRISEIO_GIT_REPOSITORY_OWNER'] = nil
134
- ENV['BITRISEIO_GIT_REPOSITORY_SLUG'] = nil
135
- ENV['BRANCH'] = nil
136
- ENV['BRANCH_NAME'] = nil
137
- ENV['BUILD_ID'] = nil
138
- ENV['BUILD_NUMBER'] = nil
139
- ENV['BUILD_NUMBER'] = nil
140
- ENV['BUILD_URL'] = nil
141
- ENV['BUILDKITE'] = nil
142
- ENV['BUILDKITE_BRANCH'] = nil
143
- ENV['BUILDKITE_JOB_ID'] = nil
144
- ENV['BUILDKITE_BUILD_NUMBER'] = nil
145
- ENV['BUILDKITE_BUILD_URL'] = nil
146
- ENV['BUILDKITE_PROJECT_SLUG'] = nil
147
- ENV['BUILDKITE_COMMIT'] = nil
148
- ENV['CI'] = 'true'
149
- ENV['CI_BRANCH'] = nil
150
- ENV['CI_BUILD_ID'] = nil
151
- ENV['CI_BUILD_NUMBER'] = nil
152
- ENV['CI_BUILD_REF'] = nil
153
- ENV['CI_BUILD_REF_NAME'] = nil
154
- ENV['CI_BUILD_REPO'] = nil
155
- ENV['CI_BUILD_URL'] = nil
156
- ENV['CI_COMMIT'] = nil
157
- ENV['CI_COMMIT_ID'] = nil
158
- ENV['CI_NAME'] = nil
159
- ENV['CI_PROJECT_DIR'] = nil
160
- ENV['CI_SERVER_NAME'] = nil
161
- ENV['CI_SERVER_NAME'] = nil
162
- ENV['CIRCLE_BRANCH'] = nil
163
- ENV['CIRCLE_BUILD_NUM'] = nil
164
- ENV['CIRCLE_NODE_INDEX'] = nil
165
- ENV['CIRCLE_PR_NUMBER'] = nil
166
- ENV['CIRCLE_PROJECT_REPONAME'] = nil
167
- ENV['CIRCLE_PROJECT_USERNAME'] = nil
168
- ENV['CIRCLE_SHA1'] = nil
169
- ENV['CIRCLECI'] = nil
170
- ENV['CODECOV_ENV'] = nil
171
- ENV['CODECOV_SLUG'] = nil
172
- ENV['CODECOV_TOKEN'] = nil
173
- ENV['CODECOV_URL'] = nil
174
- ENV['COMMIT'] = nil
175
- ENV['DRONE'] = nil
176
- ENV['DRONE_BRANCH'] = nil
177
- ENV['DRONE_BUILD_URL'] = nil
178
- ENV['DRONE_COMMIT'] = nil
179
- ENV['ghprbActualCommit'] = nil
180
- ENV['ghprbPullId'] = nil
181
- ENV['ghprbSourceBranch'] = nil
182
- ENV['GIT_BRANCH'] = nil
183
- ENV['GIT_COMMIT'] = nil
184
- ENV['GITHUB_ACTIONS'] = nil
185
- ENV['GITHUB_REF'] = nil
186
- ENV['GITHUB_HEAD_REF'] = nil
187
- ENV['GITHUB_REPOSITORY'] = nil
188
- ENV['GITHUB_RUN_ID'] = nil
189
- ENV['GITHUB_SHA'] = nil
190
- ENV['GITLAB_CI'] = nil
191
- ENV['HEROKU_TEST_RUN_ID'] = nil
192
- ENV['HEROKU_TEST_RUN_BRANCH'] = nil
193
- ENV['HEROKU_TEST_RUN_COMMIT_VERSION'] = nil
194
- ENV['JENKINS_URL'] = nil
195
- ENV['MAGNUM'] = nil
196
- ENV['PULL_REQUEST'] = nil
197
- ENV['REPO_NAME'] = nil
198
- ENV['REVISION'] = nil
199
- ENV['SEMAPHORE'] = nil
200
- ENV['SEMAPHORE_BUILD_NUMBER'] = nil
201
- ENV['SEMAPHORE_CURRENT_THREAD'] = nil
202
- ENV['SEMAPHORE_REPO_SLUG'] = nil
203
- ENV['SHIPPABLE'] = nil
204
- ENV['TF_BUILD'] = nil
205
- ENV['TRAVIS'] = nil
206
- ENV['TRAVIS_BRANCH'] = nil
207
- ENV['TRAVIS_COMMIT'] = nil
208
- ENV['TRAVIS_JOB_ID'] = nil
209
- ENV['TRAVIS_JOB_NUMBER'] = nil
210
- ENV['TRAVIS_PULL_REQUEST'] = nil
211
- ENV['TRAVIS_REPO_SLUG'] = nil
212
- ENV['VCS_COMMIT_ID'] = nil
213
- ENV['WERCKER_GIT_BRANCH'] = nil
214
- ENV['WERCKER_GIT_COMMIT'] = nil
215
- ENV['WERCKER_GIT_OWNER'] = nil
216
- ENV['WERCKER_GIT_REPOSITORY'] = nil
217
- ENV['WERCKER_MAIN_PIPELINE_STARTED'] = nil
218
- ENV['WORKSPACE'] = nil
219
-
220
- REALENV.each_pair { |k, v| ENV[k] = v }
221
- end
222
-
223
- def test_git
224
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
225
- result = upload
226
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
227
- branch = `git rev-parse --abbrev-ref HEAD`.strip
228
- assert_equal(branch != 'HEAD' ? branch : 'master', result['params'][:branch])
229
- assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
230
- end
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
-
249
- def test_travis
250
- ENV['CI'] = 'true'
251
- ENV['TRAVIS'] = 'true'
252
- ENV['TRAVIS_BRANCH'] = 'master'
253
- ENV['TRAVIS_COMMIT'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
254
- ENV['TRAVIS_JOB_ID'] = '33116958'
255
- ENV['TRAVIS_PULL_REQUEST'] = 'false'
256
- ENV['TRAVIS_JOB_NUMBER'] = '1'
257
- ENV['TRAVIS_REPO_SLUG'] = 'codecov/ci-repo'
258
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
259
- result = upload
260
- assert_equal('travis', result['params'][:service])
261
- assert_equal('c739768fcac68144a3a6d82305b9c4106934d31a', result['params'][:commit])
262
- assert_equal('codecov/ci-repo', result['params'][:slug])
263
- assert_equal('1', result['params'][:build])
264
- assert_equal('33116958', result['params'][:job])
265
- assert_equal('false', result['params'][:pull_request])
266
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
267
- end
268
-
269
- def test_codeship
270
- ENV['CI'] = 'true'
271
- ENV['CI_NAME'] = 'codeship'
272
- ENV['CI_BRANCH'] = 'master'
273
- ENV['CI_BUILD_NUMBER'] = '1'
274
- ENV['CI_COMMIT_ID'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
275
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
276
- result = upload
277
- assert_equal('codeship', result['params'][:service])
278
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
279
- assert_equal('1', result['params'][:build])
280
- assert_equal('master', result['params'][:branch])
281
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
282
- end
283
-
284
- def test_buildkite
285
- ENV['CI'] = 'true'
286
- ENV['BUILDKITE'] = 'true'
287
- ENV['BUILDKITE_BRANCH'] = 'master'
288
- ENV['BUILDKITE_BUILD_NUMBER'] = '1'
289
- ENV['BUILDKITE_JOB_ID'] = '2'
290
- ENV['BUILDKITE_BUILD_URL'] = 'http://demo'
291
- ENV['BUILDKITE_PROJECT_SLUG'] = 'owner/repo'
292
- ENV['BUILDKITE_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
293
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
294
- result = upload
295
- assert_equal('buildkite', result['params'][:service])
296
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
297
- assert_equal('1', result['params'][:build])
298
- assert_equal('2', result['params'][:job])
299
- assert_equal('master', result['params'][:branch])
300
- assert_equal('owner/repo', result['params'][:slug])
301
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
302
- end
303
-
304
- def test_jenkins
305
- ENV['JENKINS_URL'] = 'true'
306
- ENV['ghprbSourceBranch'] = 'master'
307
- ENV['BUILD_NUMBER'] = '1'
308
- ENV['ghprbActualCommit'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
309
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
310
- ENV['BUILD_URL'] = 'https://jenkins'
311
- ENV['ghprbPullId'] = '1'
312
- result = upload
313
- assert_equal('jenkins', result['params'][:service])
314
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
315
- assert_equal('1', result['params'][:build])
316
- assert_equal('1', result['params'][:pr])
317
- assert_equal('master', result['params'][:branch])
318
- assert_equal('https://jenkins', result['params'][:build_url])
319
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
320
- end
321
-
322
- def test_jenkins_2
323
- ENV['JENKINS_URL'] = 'true'
324
- ENV['GIT_BRANCH'] = 'master'
325
- ENV['BUILD_NUMBER'] = '1'
326
- ENV['GIT_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
327
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
328
- ENV['BUILD_URL'] = 'https://jenkins'
329
- result = upload
330
- assert_equal('jenkins', result['params'][:service])
331
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
332
- assert_equal('1', result['params'][:build])
333
- assert_equal('master', result['params'][:branch])
334
- assert_equal('https://jenkins', result['params'][:build_url])
335
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
336
- end
337
-
338
- def test_shippable
339
- ENV['CI'] = 'true'
340
- ENV['SHIPPABLE'] = 'true'
341
- ENV['BRANCH'] = 'master'
342
- ENV['BUILD_NUMBER'] = '1'
343
- ENV['BUILD_URL'] = 'http://shippable.com/...'
344
- ENV['PULL_REQUEST'] = 'false'
345
- ENV['REPO_NAME'] = 'owner/repo'
346
- ENV['COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
347
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
348
- result = upload
349
- assert_equal('shippable', result['params'][:service])
350
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
351
- assert_equal('false', result['params'][:pull_request])
352
- assert_equal('1', result['params'][:build])
353
- assert_equal('http://shippable.com/...', result['params'][:build_url])
354
- assert_equal('master', result['params'][:branch])
355
- assert_equal('owner/repo', result['params'][:slug])
356
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
357
- end
358
-
359
- def test_appveyor
360
- ENV['CI'] = 'True'
361
- ENV['APPVEYOR'] = 'True'
362
- ENV['APPVEYOR_REPO_BRANCH'] = 'master'
363
- ENV['APPVEYOR_JOB_ID'] = 'build'
364
- ENV['APPVEYOR_PULL_REQUEST_NUMBER'] = '1'
365
- ENV['APPVEYOR_ACCOUNT_NAME'] = 'owner'
366
- ENV['APPVEYOR_PROJECT_SLUG'] = 'repo'
367
- ENV['APPVEYOR_BUILD_VERSION'] = 'job'
368
- ENV['APPVEYOR_REPO_NAME'] = 'owner/repo'
369
- ENV['APPVEYOR_REPO_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
370
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
371
- result = upload
372
- assert_equal('appveyor', result['params'][:service])
373
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
374
- assert_equal('master', result['params'][:branch])
375
- assert_equal('owner/repo', result['params'][:slug])
376
- assert_equal('1', result['params'][:pr])
377
- assert_equal('build', result['params'][:build])
378
- assert_equal('owner/repo/job', result['params'][:job])
379
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
380
- end
381
-
382
- def test_circleci
383
- ENV['CI'] = 'true'
384
- ENV['CIRCLECI'] = 'true'
385
- ENV['CIRCLE_BRANCH'] = 'master'
386
- ENV['CIRCLE_BUILD_NUM'] = '1'
387
- ENV['CIRCLE_NODE_INDEX'] = '2'
388
- ENV['CIRCLE_PR_NUMBER'] = '3'
389
- ENV['CIRCLE_PROJECT_USERNAME'] = 'owner'
390
- ENV['CIRCLE_PROJECT_REPONAME'] = 'repo'
391
- ENV['CIRCLE_SHA1'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
392
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
393
- result = upload
394
- assert_equal('circleci', result['params'][:service])
395
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
396
- assert_equal('1', result['params'][:build])
397
- assert_equal('2', result['params'][:job])
398
- assert_equal('3', result['params'][:pr])
399
- assert_equal('master', result['params'][:branch])
400
- assert_equal('owner/repo', result['params'][:slug])
401
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
402
- end
403
-
404
- def test_semaphore
405
- ENV['CI'] = 'true'
406
- ENV['SEMAPHORE'] = 'true'
407
- ENV['BRANCH_NAME'] = 'master'
408
- ENV['SEMAPHORE_REPO_SLUG'] = 'owner/repo'
409
- ENV['SEMAPHORE_BUILD_NUMBER'] = '1'
410
- ENV['SEMAPHORE_CURRENT_THREAD'] = '2'
411
- ENV['REVISION'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
412
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
413
- result = upload
414
- assert_equal('semaphore', result['params'][:service])
415
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
416
- assert_equal('1', result['params'][:build])
417
- assert_equal('2', result['params'][:job])
418
- assert_equal('master', result['params'][:branch])
419
- assert_equal('owner/repo', result['params'][:slug])
420
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
421
- end
422
-
423
- def test_drone
424
- ENV['CI'] = 'true'
425
- ENV['DRONE'] = 'true'
426
- ENV['DRONE_BRANCH'] = 'master'
427
- ENV['DRONE_BUILD_NUMBER'] = '1'
428
- ENV['DRONE_BUILD_URL'] = 'https://drone.io/...'
429
- ENV['DRONE_COMMIT'] = '1123566'
430
- ENV['CODECOV_SLUG'] = 'codecov/ci-repo'
431
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
432
- result = upload
433
- assert_equal('drone.io', result['params'][:service])
434
- assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
435
- assert_equal('1', result['params'][:build])
436
- assert_equal('https://drone.io/...', result['params'][:build_url])
437
- assert_equal('codecov/ci-repo', result['params'][:slug])
438
- assert_equal('master', result['params'][:branch])
439
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
440
- end
441
-
442
- def test_wercker
443
- ENV['CI'] = 'true'
444
- ENV['WERCKER_GIT_BRANCH'] = 'master'
445
- ENV['WERCKER_MAIN_PIPELINE_STARTED'] = '1'
446
- ENV['WERCKER_GIT_OWNER'] = 'owner'
447
- ENV['WERCKER_GIT_REPOSITORY'] = 'repo'
448
- ENV['WERCKER_GIT_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
449
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
450
- result = upload
451
- assert_equal('wercker', result['params'][:service])
452
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
453
- assert_equal('1', result['params'][:build])
454
- assert_equal('master', result['params'][:branch])
455
- assert_equal('owner/repo', result['params'][:slug])
456
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
457
- end
458
-
459
- def test_github_pull_request
460
- ENV['CI'] = 'true'
461
- ENV['GITHUB_ACTIONS'] = 'true'
462
- ENV['GITHUB_HEAD_REF'] = 'patch-2'
463
- ENV['GITHUB_REF'] = 'refs/pull/7/merge'
464
- ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
465
- ENV['GITHUB_RUN_ID'] = '1'
466
- ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
467
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
468
- result = upload
469
- assert_equal('github-actions', result['params'][:service])
470
- assert_equal('c739768fcac68144a3a6d82305b9c4106934d31a', result['params'][:commit])
471
- assert_equal('codecov/ci-repo', result['params'][:slug])
472
- assert_equal('1', result['params'][:build])
473
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
474
- assert_equal('patch-2', result['params'][:branch])
475
- assert_equal('7', result['params'][:pr])
476
- end
477
-
478
- def test_github_push
479
- ENV['CI'] = 'true'
480
- ENV['GITHUB_ACTIONS'] = 'true'
481
- ENV['GITHUB_HEAD_REF'] = nil
482
- ENV['GITHUB_REF'] = 'refs/head/master'
483
- ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
484
- ENV['GITHUB_RUN_ID'] = '1'
485
- ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
486
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
487
- result = upload
488
- assert_equal('github-actions', result['params'][:service])
489
- assert_equal('c739768fcac68144a3a6d82305b9c4106934d31a', result['params'][:commit])
490
- assert_equal('codecov/ci-repo', result['params'][:slug])
491
- assert_equal('1', result['params'][:build])
492
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
493
- assert_equal('master', result['params'][:branch])
494
- assert_equal(false, result['params'].key?(:pr))
495
- end
496
-
497
- def test_gitlab
498
- ENV['GITLAB_CI'] = 'true'
499
- ENV['CI_BUILD_REF_NAME'] = 'master'
500
- ENV['CI_BUILD_ID'] = '1'
501
- ENV['CI_BUILD_REPO'] = 'https://gitlab.com/owner/repo.git'
502
- ENV['CI_BUILD_REF'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
503
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
504
- result = upload
505
- assert_equal('gitlab', result['params'][:service])
506
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
507
- assert_equal('1', result['params'][:build])
508
- assert_equal('master', result['params'][:branch])
509
- assert_equal('owner/repo', result['params'][:slug])
510
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
511
- end
512
-
513
- def test_bitrise
514
- ENV['CI'] = 'true'
515
- ENV['BITRISE_IO'] = 'true'
516
- ENV['BITRISE_BUILD_NUMBER'] = '1'
517
- ENV['BITRISE_BUILD_URL'] = 'https://app.bitrise.io/build/123'
518
- ENV['BITRISE_GIT_BRANCH'] = 'master'
519
- ENV['BITRISE_PULL_REQUEST'] = '2'
520
- ENV['BITRISEIO_GIT_REPOSITORY_OWNER'] = 'owner'
521
- ENV['BITRISEIO_GIT_REPOSITORY_SLUG'] = 'repo'
522
- ENV['BITRISE_GIT_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
523
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
524
- result = upload
525
- assert_equal('bitrise', result['params'][:service])
526
- assert_equal('1', result['params'][:build])
527
- assert_equal('https://app.bitrise.io/build/123', result['params'][:build_url])
528
- assert_equal('master', result['params'][:branch])
529
- assert_equal('2', result['params'][:pr])
530
- assert_equal('owner/repo', result['params'][:slug])
531
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
532
- end
533
-
534
- def test_teamcity
535
- ENV['CI_SERVER_NAME'] = 'TeamCity'
536
- ENV['TEAMCITY_BUILD_BRANCH'] = 'master'
537
- ENV['TEAMCITY_BUILD_ID'] = '1'
538
- ENV['TEAMCITY_BUILD_URL'] = 'http://teamcity/...'
539
- ENV['TEAMCITY_BUILD_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
540
- ENV['TEAMCITY_BUILD_REPOSITORY'] = 'https://github.com/owner/repo.git'
541
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
542
- result = upload
543
- assert_equal('teamcity', result['params'][:service])
544
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
545
- assert_equal('1', result['params'][:build])
546
- assert_equal('master', result['params'][:branch])
547
- assert_equal('owner/repo', result['params'][:slug])
548
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
549
- end
550
-
551
- def test_azure_pipelines
552
- ENV['TF_BUILD'] = '1'
553
- ENV['BUILD_SOURCEBRANCH'] = 'master'
554
- ENV['SYSTEM_JOBID'] = '92a2fa25-f940-5df6-a185-81eb9ae2031d'
555
- ENV['BUILD_BUILDID'] = '1'
556
- ENV['SYSTEM_TEAMFOUNDATIONSERVERURI'] = 'https://dev.azure.com/codecov/'
557
- ENV['SYSTEM_TEAMPROJECT'] = 'repo'
558
- ENV['BUILD_SOURCEVERSION'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
559
- ENV['BUILD_REPOSITORY_ID'] = 'owner/repo'
560
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
561
- result = upload
562
- assert_equal('azure_pipelines', result['params'][:service])
563
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
564
- assert_equal('1', result['params'][:build])
565
- assert_equal('master', result['params'][:branch])
566
- assert_equal('owner/repo', result['params'][:slug])
567
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
568
- end
569
-
570
- def test_heroku
571
- ENV['HEROKU_TEST_RUN_ID'] = '454f5dc9-afa4-433f-bb28-84678a00fd98'
572
- ENV['HEROKU_TEST_RUN_BRANCH'] = 'master'
573
- ENV['HEROKU_TEST_RUN_COMMIT_VERSION'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
574
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
575
-
576
- result = upload
577
- assert_equal('heroku', result['params'][:service])
578
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
579
- assert_equal('454f5dc9-afa4-433f-bb28-84678a00fd98', result['params'][:build])
580
- assert_equal('master', result['params'][:branch])
581
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
582
- end
583
-
584
- def test_bitbucket_pr
585
- ENV['CI'] = 'true'
586
- ENV['BITBUCKET_BUILD_NUMBER'] = '100'
587
- ENV['BITBUCKET_BRANCH'] = 'master'
588
- ENV['BITBUCKET_COMMIT'] = '743b04806ea67'
589
- ENV['VCS_COMMIT_ID'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
590
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
591
-
592
- result = upload
593
- assert_equal('bitbucket', result['params'][:service])
594
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
595
- assert_equal('100', result['params'][:build])
596
- assert_equal('master', result['params'][:branch])
597
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
598
- end
599
-
600
- def test_bitbucket
601
- ENV['CI'] = 'true'
602
- ENV['BITBUCKET_BUILD_NUMBER'] = '100'
603
- ENV['BITBUCKET_BRANCH'] = 'master'
604
- ENV['BITBUCKET_COMMIT'] = '743b04806ea677403aa2ff26c6bdeb85005de658'
605
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
606
-
607
- result = upload
608
- assert_equal('bitbucket', result['params'][:service])
609
- assert_equal('743b04806ea677403aa2ff26c6bdeb85005de658', result['params'][:commit])
610
- assert_equal('100', result['params'][:build])
611
- assert_equal('master', result['params'][:branch])
612
- assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
613
- end
614
-
615
- def test_filenames_are_shortened_correctly
616
- ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
617
-
618
- formatter = SimpleCov::Formatter::Codecov.new
619
- result = stub('SimpleCov::Result', files: [
620
- stub_file('/path/lib/something.rb', []),
621
- stub_file('/path/path/lib/path_somefile.rb', [])
622
- ])
623
- SimpleCov.stubs(:root).returns('/path')
624
- data = formatter.format(result)
625
- puts data
626
- puts data['params']
627
- assert_equal(data['coverage'].to_json, {
628
- 'lib/something.rb' => [nil],
629
- 'path/lib/path_somefile.rb' => [nil]
630
- }.to_json)
631
- end
632
-
633
- def test_invalid_token
634
- stub_request(:post, %r{https:\/\/codecov.io\/upload})
635
- .to_return(
636
- status: 400,
637
- body: "HTTP 400\n" \
638
- 'Provided token is not a UUID.'
639
- )
640
-
641
- ENV['CODECOV_TOKEN'] = 'fake'
642
- result = upload(false)
643
- assert_equal(false, result['result']['uploaded'])
644
- branch = `git rev-parse --abbrev-ref HEAD`.strip
645
- assert_equal(branch != 'HEAD' ? branch : 'master', result['params'][:branch])
646
- assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
647
- end
648
- end