Skip to content

Commit

Permalink
Set MA0032 to warning: Use an overload with a CancellationToken argument
Browse files Browse the repository at this point in the history
  • Loading branch information
edumserrano committed Apr 6, 2024
1 parent 88682e5 commit 1706480
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions MarkdownLinkCheckLogParser/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ dotnet_diagnostic.SA1651.severity = suggestion # SA1651: Do not use placeho
# See https://github.com/meziantou/Meziantou.Analyzer/tree/main/docs
##########################################
[*.cs]
dotnet_diagnostic.MA0032.severity = none # MA0032 Use an overload with a CancellationToken argument
dotnet_diagnostic.MA0051.severity = none # MA0051 Method is too long

##########################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async ValueTask ExecuteAsync(IConsole console)
using var httpClient = _httpClient ?? GitHubHttpClient.CreateHttpClient(authToken);
var gitHubHttpClient = new GitHubHttpClient(httpClient);
var gitHubWorkflowRunLogs = new GitHubWorkflowRunLogs(gitHubHttpClient);
var stepLog = await gitHubWorkflowRunLogs.GetStepLogAsync(repo, runId, jobName, stepName);
var stepLog = await gitHubWorkflowRunLogs.GetStepLogAsync(repo, runId, jobName, stepName, CancellationToken.None);
var output = MarkdownLinkCheckOutputParser.Parse(stepLog, CaptureErrorsOnly);
foreach (var outputFormat in outputFormats)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ public static HttpClient CreateHttpClient(GitHubAuthToken authToken)
}

// see https://docs.github.com/en/rest/actions/workflow-runs#download-workflow-run-logs
public async Task<ZipArchive> DownloadWorkflowRunLogsAsync(GitHubRepository repo, GitHubRunId runId)
public async Task<ZipArchive> DownloadWorkflowRunLogsAsync(
GitHubRepository repo,
GitHubRunId runId,
CancellationToken cancellationToken)
{
repo.NotNull();
runId.NotNull();

using var httpRequest = new HttpRequestMessage(HttpMethod.Get, $"repos/{repo}/actions/runs/{runId}/logs");
var httpResponse = await _httpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead);
var httpResponse = await _httpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
if (!httpResponse.IsSuccessStatusCode)
{
throw new GitHubHttpClientException(httpRequest.Method, httpRequest.RequestUri, httpResponse.StatusCode);
}

var responseStream = await httpResponse.Content.ReadAsStreamAsync();
var responseStream = await httpResponse.Content.ReadAsStreamAsync(cancellationToken);
return new ZipArchive(responseStream, ZipArchiveMode.Read);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ public GitHubWorkflowRunLogs(GitHubHttpClient gitHubHttpClient)
GitHubRepository repo,
GitHubRunId runId,
GitHubJobName jobName,
GitHubStepName stepName)
GitHubStepName stepName,
CancellationToken cancellationToken)
{
repo.NotNull();
runId.NotNull();
jobName.NotNull();
stepName.NotNull();

using var workflowRunLogsZip = await _gitHubHttpClient.DownloadWorkflowRunLogsAsync(repo, runId);
using var workflowRunLogsZip = await _gitHubHttpClient.DownloadWorkflowRunLogsAsync(repo, runId, cancellationToken);
var markdownLinkCheckLogsZipEntrys = workflowRunLogsZip.Entries.
Where(e => e.FullName.Contains($"{jobName}/", StringComparison.InvariantCultureIgnoreCase) && e.Name.Contains(stepName, StringComparison.InvariantCultureIgnoreCase))
.ToList();
Expand All @@ -38,7 +39,7 @@ public GitHubWorkflowRunLogs(GitHubHttpClient gitHubHttpClient)
await using var logAsStream = logAsZip.Open();
using var streamReader = new StreamReader(logAsStream, Encoding.UTF8);
var memory = new Memory<char>(new char[logAsZip.Length]);
await streamReader.ReadAsync(memory);
await streamReader.ReadAsync(memory, cancellationToken);
return new GitHubStepLog(memory);
}
}

0 comments on commit 1706480

Please sign in to comment.