Skip to content

Commit

Permalink
style: Update Snapshot comment instead of adding it
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM committed Feb 14, 2024
1 parent 4d969fd commit 8f6584a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions github-actions-helpers/Build.Github.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ await client.Issue.Update(
markdown.Append("```").AppendLine();
}

await HideCommentsInPullRequest(PullRequestNumber.Value, "## Snapshots difference");
await PostCommentToPullRequest(PullRequestNumber.Value, markdown.ToString());
await PostOrModifyPullRequestCommand(PullRequestNumber.Value, markdown.ToString());

void RecordChange(StringBuilder diffsInFile, Dictionary<string, int> diffCounts)
{
Expand Down Expand Up @@ -178,6 +177,35 @@ string CleanValue(string value)
}
});

async Task PostOrModifyPullRequestCommand(int prNumber, string markdown)
{
var client = GetGitHubClient();
var comments = await client.Issue.Comment.GetAllForIssue(
owner: GitHubRepositoryOwner,
name: GitHubRepositoryName,
number: prNumber);

var existingComment = comments.LastOrDefault(c => c.Body.StartsWith("## Snapshots difference"));
if (existingComment is not null)
{
Console.WriteLine("Found existing comment, updating");
await client.Issue.Comment.Update(
owner: GitHubRepositoryOwner,
name: GitHubRepositoryName,
commentId: existingComment.Id,

Check failure on line 195 in github-actions-helpers/Build.Github.cs

View workflow job for this annotation

GitHub Actions / check-snapshots

The best overload for 'Update' does not have a parameter named 'commentId'

Check failure on line 195 in github-actions-helpers/Build.Github.cs

View workflow job for this annotation

GitHub Actions / add-labels

The best overload for 'Update' does not have a parameter named 'commentId'
markdown);
}
else
{
Console.WriteLine("Posting new comment");
await client.Issue.Comment.Create(
owner: GitHubRepositoryOwner,
name: GitHubRepositoryName,
prNumber,
markdown);
}
}

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

0 comments on commit 8f6584a

Please sign in to comment.