forked from codecov/codecov-exe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable-s3 argument to use V2 of the API
- Loading branch information
Showing
21 changed files
with
268 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Net; | ||
using System.Text; | ||
using Codecov.Coverage.Report; | ||
using Codecov.Logger; | ||
using Codecov.Url; | ||
|
||
namespace Codecov.Upload | ||
{ | ||
internal class HttpWebRequestV2 : UploadV2 | ||
{ | ||
public HttpWebRequestV2(IUrl url, IReport report) | ||
: base(url, report) | ||
{ | ||
} | ||
|
||
protected override string Post() | ||
{ | ||
Log.Verboase("Trying to upload using HttpWebRequest."); | ||
|
||
var postRequest = (System.Net.HttpWebRequest)WebRequest.Create(Uri); | ||
postRequest.ContentType = "text/plain"; | ||
postRequest.Method = "POST"; | ||
postRequest.Headers["Content-Encoding"] = "gzip"; | ||
postRequest.Headers["X-Content-Encoding"] = "gzip"; | ||
postRequest.Headers["Accept"] = "text/plain"; | ||
|
||
using (var putStreamWriter = new GZipStream(postRequest.GetRequestStreamAsync().Result, CompressionLevel.Optimal)) | ||
{ | ||
var content = Encoding.UTF8.GetBytes(Report.Reporter); | ||
putStreamWriter.Write(content, 0, content.Length); | ||
} | ||
|
||
var postResponse = (HttpWebResponse)postRequest.GetResponseAsync().Result; | ||
|
||
if (postResponse.StatusCode != HttpStatusCode.OK) | ||
{ | ||
Log.Verboase("Failed to upload the report."); | ||
return string.Empty; | ||
} | ||
|
||
using (var postStreamReader = new StreamReader(postResponse.GetResponseStream())) | ||
{ | ||
return postStreamReader.ReadToEnd(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Codecov.Coverage.Report; | ||
using Codecov.Logger; | ||
using Codecov.Url; | ||
|
||
namespace Codecov.Upload | ||
{ | ||
internal abstract class UploadV2 : IUpload | ||
{ | ||
private readonly Lazy<IReport> _report; | ||
|
||
private readonly Lazy<IUrl> _url; | ||
|
||
protected UploadV2(IUrl url, IReport report) | ||
{ | ||
_url = new Lazy<IUrl>(() => url); | ||
_report = new Lazy<IReport>(() => report); | ||
} | ||
|
||
protected IReport Report => _report.Value; | ||
|
||
protected Uri Uri => _url.Value.GetUrl(ApiVersion.V2); | ||
|
||
private string DisplayUrl | ||
{ | ||
get | ||
{ | ||
var url = Uri.ToString(); | ||
var regex = new Regex(@"token=\w{8}-\w{4}-\w{4}-\w{4}-\w{12}&"); | ||
return regex.Replace(url, string.Empty); | ||
} | ||
} | ||
|
||
public string Uploader() | ||
{ | ||
Log.Information($"url: {Uri.Scheme}://{Uri.Authority}"); | ||
Log.Verboase($"api endpoint: {Uri}"); | ||
Log.Information($"query: {DisplayUrl}"); | ||
|
||
try | ||
{ | ||
var response = Post(); | ||
if (string.IsNullOrWhiteSpace(response)) | ||
{ | ||
Log.Verboase("Failed to ping codecov."); | ||
return string.Empty; | ||
} | ||
|
||
return response; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.VerboaseException(ex); | ||
return string.Empty; | ||
} | ||
} | ||
|
||
protected abstract string Post(); | ||
} | ||
} |
Oops, something went wrong.