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

Commit

Permalink
Fix enterprise issue and bump to 0.2.7 (#93)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thomasrockhu authored Aug 21, 2020
1 parent f256e68 commit e0b8889
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### `0.2.7`
- Fix for enterprise users unable to upload using the v4 uploader

### `0.2.6`
- Fix issue with `push` events on GitHub Actions

Expand Down
2 changes: 1 addition & 1 deletion codecov.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>=2.4'
s.summary = 'hosted code coverage ruby/rails reporter'
s.test_files = ['test/test_codecov.rb']
s.version = '0.2.6'
s.version = '0.2.7'

s.add_dependency 'colorize'
s.add_dependency 'json'
Expand Down
13 changes: 9 additions & 4 deletions lib/codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'zlib'

class SimpleCov::Formatter::Codecov
VERSION = '0.2.6'
VERSION = '0.2.7'

### CIs
RECOGNIZED_CIS = [
Expand Down Expand Up @@ -337,6 +337,7 @@ def gzip_report(report)

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

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

response = upload_to_v4(url, gzipped_report, query, query_without_token)
return false if response == false
response = false
unless is_enterprise
response = upload_to_v4(url, gzipped_report, query, query_without_token)
return false if response == false
end

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

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

req = Net::HTTP::Post.new(
"#{uri.path}?#{query}",
{
'Accept' => 'application/json',
'Content-Encoding' => 'gzip',
'Content-Type' => 'text/plain',
'X-Content-Encoding' => 'gzip'
Expand Down
19 changes: 18 additions & 1 deletion test/test_codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def upload(success = true)
end

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

def test_enterprise
stub = stub_request(:post, %r{https:\/\/example.com\/upload\/v2})
.to_return(
status: 200,
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\"}"
)

ENV['CODECOV_URL'] = 'https://example.com'
ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
result = upload
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
assert_equal('12345678-1234-abcd-ef12-1234567890ab', result['result']['id'])
branch = `git rev-parse --abbrev-ref HEAD`.strip
assert_equal(branch != 'HEAD' ? branch : 'master', result['params'][:branch])
assert_equal(`git rev-parse HEAD`.strip, result['params'][:commit])
end

def test_travis
ENV['CI'] = 'true'
ENV['TRAVIS'] = 'true'
Expand Down

0 comments on commit e0b8889

Please sign in to comment.