Skip to content

Commit

Permalink
refactor: Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM committed Feb 14, 2024
1 parent 5a249b6 commit 1c20447
Showing 1 changed file with 0 additions and 87 deletions.
87 changes: 0 additions & 87 deletions github-actions-helpers/Build.Github.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,93 +206,6 @@ await client.Issue.Comment.Create(
}
}

async Task PostCommentToPullRequest(int prNumber, string markdown)
{
Console.WriteLine("Posting comment to GitHub");

// post directly to GitHub as
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
httpClient.DefaultRequestHeaders.Add("Authorization", $"token {GitHubToken}");
httpClient.DefaultRequestHeaders.UserAgent.Add(new(new System.Net.Http.Headers.ProductHeaderValue("nuke-ci-client")));

var url = $"https://api.github.com/repos/{GitHubRepositoryOwner}/{GitHubRepositoryName}/issues/{prNumber}/comments";
Console.WriteLine($"Sending request to '{url}'");

var result = await httpClient.PostAsJsonAsync(url, new { body = markdown });

if (result.IsSuccessStatusCode)
{
Console.WriteLine("Comment posted successfully");
}
else
{
var response = await result.Content.ReadAsStringAsync();
Console.WriteLine("Error: " + response);
result.EnsureSuccessStatusCode();
}
}

async Task HideCommentsInPullRequest(int prNumber, string prefix)
{
try
{
Console.WriteLine("Looking for comments to hide in GitHub");

var clientId = "nuke-ci-client";
var productInformation = Octokit.GraphQL.ProductHeaderValue.Parse(clientId);
var connection = new Octokit.GraphQL.Connection(productInformation, GitHubToken);

var query = new Octokit.GraphQL.Query()
.Repository(GitHubRepositoryName, GitHubRepositoryOwner)
.PullRequest(prNumber)
.Comments()
.AllPages()
.Select(issue => new { issue.Id, issue.Body, issue.IsMinimized, });

var issueComments = (await connection.Run(query)).ToList();

Console.WriteLine($"Found {issueComments} comments for PR {prNumber}");

var count = 0;
foreach (var issueComment in issueComments)
{
if (issueComment.IsMinimized || ! issueComment.Body.StartsWith(prefix))
{
continue;
}

try
{
var arg = new MinimizeCommentInput
{
Classifier = ReportedContentClassifiers.Outdated,
SubjectId = issueComment.Id,
ClientMutationId = clientId
};

var mutation = new Mutation()
.MinimizeComment(arg)
.Select(x => new { x.MinimizedComment.IsMinimized });

await connection.Run(mutation);
count++;

}
catch (Exception ex)
{
Logger.Warning($"Error minimising comment with ID {issueComment.Id}: {ex}");
}
}

Console.WriteLine($"Minimised {count} comments for PR {prNumber}");
}
catch (Exception ex)
{
Logger.Warning($"There was an error trying to minimise old comments with prefix '{prefix}': {ex}");
}
}

Target AssignLabelsToPullRequest => _ => _
.Unlisted()
.Requires(() => GitHubRepositoryName)
Expand Down

0 comments on commit 1c20447

Please sign in to comment.