Skip to content

Commit

Permalink
Update Codecov upload API to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Feb 13, 2021
1 parent d762754 commit d3ca8a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/codecovio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ module Codecov
@debug "Codecov.io API URL:\n" * mask_token(uri_str)

if !dry_run
heads = Dict("Content-Type" => "application/json",
"Accept" => "application/json")
data = to_json(fcs)
req = HTTP.post(uri_str; body = JSON.json(data), headers = heads)
@debug "Result of submission:" * String(req)
# Tell Codecov we have an upload for them
response = HTTP.post(uri_str; headers=Dict("Accept" => "text/plain"))
# Get the temporary URL to use for uploading to S3
s3url = split(String(response.body), '\n')[2]
# Upload to S3
request = HTTP.put(s3url; body=json(to_json(fcs)),
header=Dict("Content-Type" => "application/json",
"x-amz-storage-class" => "REDUCED_REDUNDANCY"))
@debug "Result of submission:" * String(request)
end
end

Expand All @@ -246,7 +250,7 @@ module Codecov
codecov_url = get(kwargs, :codecov_url, "https://codecov.io")
codecov_url[end] == "/" && error("the codecov_url should not end with a /, given url $(repr(codecov_url))")

uri_str = "$(codecov_url)/upload/v2?"
uri_str = "$(codecov_url)/upload/v4?"
for (k, v) in kwargs
# add all except a few special key/value pairs to the URL
# (:verbose is there for backwards compatibility with versions
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ withenv(

# in the case above, the token is at the end. Let's test explicitly,
# that this also works if the token occurs earlier in the url
url = "https://enterprise-codecov-1.com/upload/v2?token=token_name_1&build=t_job_num"
url = "https://enterprise-codecov-1.com/upload/v4?token=token_name_1&build=t_job_num"
masked = Coverage.Codecov.mask_token(url)
@test masked == "https://enterprise-codecov-1.com/upload/v2?token=<HIDDEN>&build=t_job_num"
@test masked == "https://enterprise-codecov-1.com/upload/v4?token=<HIDDEN>&build=t_job_num"
end


Expand Down

0 comments on commit d3ca8a2

Please sign in to comment.