Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit f26de18

Browse files
authored
Merge pull request #2 from codacy/luis-ferreira/hotfix-useless-async
Make some final fixes
2 parents 2849669 + c76ede5 commit f26de18

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This is the parameters list:
2020
- `-r`, `--report`: Path to the coverage report _(Required)_
2121
- `-e`, `--engine`: Engine Report Type (dotcover, opencover). _(Required)_
2222
- `-p`, `--partial`: Send report as a partial report _(Default: false)_
23+
- `-f`, `--final`: Send final coverage request _(Default: false)_
2324
- `--help`: Display this help screen.
2425
- `--version`: Display version information.
2526

src/Program.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Net;
33
using System.Net.Http;
44
using System.Text;
5-
using System.Threading.Tasks;
65
using Codacy.CSharpCoverage.Models.Result;
76
using Codacy.CSharpCoverage.Parsing.Processors;
87
using CommandLine;
@@ -15,11 +14,11 @@ private static void Main(string[] args)
1514
{
1615
// parse the option arguments
1716
Parser.Default.ParseArguments<Options>(args)
18-
.WithParsed(async opt =>
17+
.WithParsed(opt =>
1918
{
2019
if (opt.Final)
2120
{
22-
await MakeFinalRequest(opt.CommitUUID, opt.Token).ConfigureAwait(false);
21+
MakeFinalRequest(opt.CommitUUID, opt.Token);
2322
}
2423
else if (string.IsNullOrEmpty(opt.ReportFile))
2524
{
@@ -53,7 +52,7 @@ private static void Main(string[] args)
5352
"Unrecognized report format, please choose dotcover or opencover");
5453
}
5554

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

82-
await MakeReportRequest(report.ToString(), commitUuid, projectToken, isPartial).ConfigureAwait(false);
81+
MakeReportRequest(report.ToString(), commitUuid, projectToken, isPartial);
8382

8483
Console.WriteLine(report.GetStats());
8584
}
@@ -113,10 +112,10 @@ private static string GetBaseApiOrDefault()
113112
/// <param name="commitUuid">commit uuid</param>
114113
/// <param name="projectToken">project token</param>
115114
/// <returns>an async http response</returns>
116-
private static async Task<HttpResponseMessage> MakeFinalRequest(string commitUuid, string projectToken)
115+
private static HttpResponseMessage MakeFinalRequest(string commitUuid, string projectToken)
117116
{
118-
return await MakeRequest("", $"{GetBaseApiOrDefault()}/2.0/commit/{commitUuid}/coverageFinal",
119-
projectToken).ConfigureAwait(false);
117+
return MakeRequest("{}", $"/2.0/commit/{commitUuid}/coverageFinal",
118+
projectToken);
120119
}
121120

122121
/// <summary>
@@ -128,14 +127,14 @@ private static async Task<HttpResponseMessage> MakeFinalRequest(string commitUui
128127
/// <param name="projectToken">project token</param>
129128
/// <param name="isPartial">partial flag</param>
130129
/// <returns></returns>
131-
private static async Task<HttpResponseMessage> MakeReportRequest(string json, string commitUuid,
130+
private static HttpResponseMessage MakeReportRequest(string json, string commitUuid,
132131
string projectToken,
133132
bool isPartial)
134133
{
135134
var partial = isPartial ? "true" : "false";
136135

137-
return await MakeRequest(json,
138-
$"/2.0/coverage/{commitUuid}/CSharp?partial={partial}", projectToken).ConfigureAwait(false);
136+
return MakeRequest(json,
137+
$"/2.0/coverage/{commitUuid}/CSharp?partial={partial}", projectToken);
139138
}
140139

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

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

163162
Console.WriteLine(res.Content);
164163
Console.WriteLine("Response status: " + res.StatusCode);

0 commit comments

Comments
 (0)