Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This is the parameters list:
- `-r`, `--report`: Path to the coverage report _(Required)_
- `-e`, `--engine`: Engine Report Type (dotcover, opencover). _(Required)_
- `-p`, `--partial`: Send report as a partial report _(Default: false)_
- `-f`, `--final`: Send final coverage request _(Default: false)_
- `--help`: Display this help screen.
- `--version`: Display version information.

Expand Down
27 changes: 13 additions & 14 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Codacy.CSharpCoverage.Models.Result;
using Codacy.CSharpCoverage.Parsing.Processors;
using CommandLine;
Expand All @@ -15,11 +14,11 @@ private static void Main(string[] args)
{
// parse the option arguments
Parser.Default.ParseArguments<Options>(args)
.WithParsed(async opt =>
.WithParsed(opt =>
{
if (opt.Final)
{
await MakeFinalRequest(opt.CommitUUID, opt.Token).ConfigureAwait(false);
MakeFinalRequest(opt.CommitUUID, opt.Token);
}
else if (string.IsNullOrEmpty(opt.ReportFile))
{
Expand Down Expand Up @@ -53,7 +52,7 @@ private static void Main(string[] args)
"Unrecognized report format, please choose dotcover or opencover");
}

await SendReport(report, opt.CommitUUID, opt.Token, opt.Partial).ConfigureAwait(false);
SendReport(report, opt.CommitUUID, opt.Token, opt.Partial);
}
});
}
Expand All @@ -67,7 +66,7 @@ private static void Main(string[] args)
/// <param name="isPartial">partial flag</param>
/// <exception cref="FormatException">if it's passed an invalid commit uuid or project token</exception>
/// <exception cref="HttpRequestException">if the api response status code is not 200.</exception>
private static async Task SendReport(CodacyReport report, string commitUuid, string projectToken, bool isPartial)
private static void SendReport(CodacyReport report, string commitUuid, string projectToken, bool isPartial)
{
if (string.IsNullOrEmpty(commitUuid))
{
Expand All @@ -79,7 +78,7 @@ private static async Task SendReport(CodacyReport report, string commitUuid, str
throw new FormatException("Invalid project token");
}

await MakeReportRequest(report.ToString(), commitUuid, projectToken, isPartial).ConfigureAwait(false);
MakeReportRequest(report.ToString(), commitUuid, projectToken, isPartial);

Console.WriteLine(report.GetStats());
}
Expand Down Expand Up @@ -113,10 +112,10 @@ private static string GetBaseApiOrDefault()
/// <param name="commitUuid">commit uuid</param>
/// <param name="projectToken">project token</param>
/// <returns>an async http response</returns>
private static async Task<HttpResponseMessage> MakeFinalRequest(string commitUuid, string projectToken)
private static HttpResponseMessage MakeFinalRequest(string commitUuid, string projectToken)
{
return await MakeRequest("", $"{GetBaseApiOrDefault()}/2.0/commit/{commitUuid}/coverageFinal",
projectToken).ConfigureAwait(false);
return MakeRequest("{}", $"/2.0/commit/{commitUuid}/coverageFinal",
projectToken);
}

/// <summary>
Expand All @@ -128,14 +127,14 @@ private static async Task<HttpResponseMessage> MakeFinalRequest(string commitUui
/// <param name="projectToken">project token</param>
/// <param name="isPartial">partial flag</param>
/// <returns></returns>
private static async Task<HttpResponseMessage> MakeReportRequest(string json, string commitUuid,
private static HttpResponseMessage MakeReportRequest(string json, string commitUuid,
string projectToken,
bool isPartial)
{
var partial = isPartial ? "true" : "false";

return await MakeRequest(json,
$"/2.0/coverage/{commitUuid}/CSharp?partial={partial}", projectToken).ConfigureAwait(false);
return MakeRequest(json,
$"/2.0/coverage/{commitUuid}/CSharp?partial={partial}", projectToken);
}

/// <summary>
Expand All @@ -147,7 +146,7 @@ private static async Task<HttpResponseMessage> MakeReportRequest(string json, st
/// <param name="endpoint">api endpoint</param>
/// <param name="projectToken">project token</param>
/// <returns></returns>
private static async Task<HttpResponseMessage> MakeRequest(string content, string endpoint, string projectToken)
private static HttpResponseMessage MakeRequest(string content, string endpoint, string projectToken)
{
//prepare url with base api url and the endpoint
var destUri = new Uri($"{GetBaseApiOrDefault()}{endpoint}");
Expand All @@ -158,7 +157,7 @@ private static async Task<HttpResponseMessage> MakeRequest(string content, strin
client.DefaultRequestHeaders.Add("project_token", projectToken);

//post request
var res = await client.PostAsync(destUri, new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false);
var res = client.PostAsync(destUri, new StringContent(content, Encoding.UTF8, "application/json")).Result;

Console.WriteLine(res.Content);
Console.WriteLine("Response status: " + res.StatusCode);
Expand Down