From 5baa28324d0e97682f6db9ab49b4f83f3221ad32 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 13 Feb 2021 13:21:13 -0800 Subject: [PATCH 1/2] Update Codecov upload API to v4 --- src/codecovio.jl | 15 ++++++++++----- test/runtests.jl | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/codecovio.jl b/src/codecovio.jl index a28496d..aedabd9 100644 --- a/src/codecovio.jl +++ b/src/codecovio.jl @@ -224,10 +224,15 @@ module Codecov @debug "Codecov.io API URL:\n" * mask_token(uri_str) if !dry_run - heads = Dict("Content-Type" => "application/json") - data = to_json(fcs) - req = HTTP.post(uri_str; body = JSON.json(data), headers = heads) - @debug "Result of submission:" * mask_token(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:" * mask_token(String(request)) end end @@ -252,7 +257,7 @@ module Codecov error("the codecov_url should not end with a /, given url $(repr(codecov_url))") end - codecov_url_path = get(kwargs, :codecov_url_path, "/upload/v2") + codecov_url_path = get(kwargs, :codecov_url_path, "/upload/v4") if isempty(codecov_url_path) || codecov_url_path[1] != '/' || codecov_url_path[end] == '/' error("the codecov_url_path should begin with, but not end with, a /, given url $(repr(codecov_url_path))") end diff --git a/test/runtests.jl b/test/runtests.jl index 1b4ede7..7a8cd17 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -430,9 +430,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=&build=t_job_num" + @test masked == "https://enterprise-codecov-1.com/upload/v4?token=&build=t_job_num" end From 9c2e0921853d015eca3e8ad69942dea0de868d5b Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 26 Feb 2021 14:00:50 -0800 Subject: [PATCH 2/2] Make Jamesonier thanks bud Co-authored-by: Jameson Nash --- src/codecovio.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/codecovio.jl b/src/codecovio.jl index aedabd9..2c170d8 100644 --- a/src/codecovio.jl +++ b/src/codecovio.jl @@ -227,7 +227,11 @@ module Codecov # 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] + repr = String(response) + s3url = get(split(String(response.body), '\n'), 2, "") + repr = chomp(replace(repr, s3url => "")) + @debug "Result of submission:" * repr + startswith(s3url, "https://") || error("Invalid codecov response: $s3url") # Upload to S3 request = HTTP.put(s3url; body=json(to_json(fcs)), header=Dict("Content-Type" => "application/json",