Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit e0b8889

Browse files
authored
Fix enterprise issue and bump to 0.2.7 (#93)
* Fix enterprise issue and bump to 0.2.7 * Stub enterprise response * Use proper response * Fix v2 response * Oops * Maybe this is right * Move to json * force
1 parent f256e68 commit e0b8889

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### `0.2.7`
2+
- Fix for enterprise users unable to upload using the v4 uploader
3+
14
### `0.2.6`
25
- Fix issue with `push` events on GitHub Actions
36

codecov.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
1313
s.required_ruby_version = '>=2.4'
1414
s.summary = 'hosted code coverage ruby/rails reporter'
1515
s.test_files = ['test/test_codecov.rb']
16-
s.version = '0.2.6'
16+
s.version = '0.2.7'
1717

1818
s.add_dependency 'colorize'
1919
s.add_dependency 'json'

lib/codecov.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
require 'zlib'
99

1010
class SimpleCov::Formatter::Codecov
11-
VERSION = '0.2.6'
11+
VERSION = '0.2.7'
1212

1313
### CIs
1414
RECOGNIZED_CIS = [
@@ -337,6 +337,7 @@ def gzip_report(report)
337337

338338
def upload_to_codecov(ci, report)
339339
url = ENV['CODECOV_URL'] || 'https://codecov.io'
340+
is_enterprise = url != 'https://codecov.io'
340341

341342
params = build_params(ci)
342343
params_secret_token = params.clone
@@ -354,8 +355,11 @@ def upload_to_codecov(ci, report)
354355
puts " url: #{url}"
355356
puts " query: #{query_without_token}"
356357

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
359363

360364
response || upload_to_v2(url, gzipped_report, query, query_without_token)
361365
end
@@ -421,11 +425,12 @@ def upload_to_v2(url, report, query, query_without_token)
421425
https.use_ssl = !url.match(/^https/).nil?
422426

423427
puts ['-> '.green, 'Uploading to Codecov'].join(' ')
424-
puts "#{url}/#{uri.path}?#{query_without_token}"
428+
puts "#{url}#{uri.path}?#{query_without_token}"
425429

426430
req = Net::HTTP::Post.new(
427431
"#{uri.path}?#{query}",
428432
{
433+
'Accept' => 'application/json',
429434
'Content-Encoding' => 'gzip',
430435
'Content-Type' => 'text/plain',
431436
'X-Content-Encoding' => 'gzip'

test/test_codecov.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def upload(success = true)
8080
end
8181

8282
def success_stubs
83-
stub_request(:post, %r{https:\/\/codecov.io\/upload})
83+
stub_request(:post, %r{https:\/\/codecov.io\/upload\/v4})
8484
.to_return(
8585
status: 200,
8686
body: "https://codecov.io/gh/fake\n" \
@@ -229,6 +229,23 @@ def test_git
229229
assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
230230
end
231231

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+
232249
def test_travis
233250
ENV['CI'] = 'true'
234251
ENV['TRAVIS'] = 'true'

0 commit comments

Comments
 (0)