From 32226fa3a7688dcbcced020fb9a83ed8d0669861 Mon Sep 17 00:00:00 2001 From: NoRePercussions Date: Wed, 17 Jul 2024 10:15:10 -0400 Subject: [PATCH] Always move ID comment to end of message (#1362) Having the comment in the middle of a message causes issues with Markdown rendering (#1362). Instead, remove all previous identifiers and re-add the comment at the end of the message. This change is backwards compatible and will automatically repair messages generated by a previous version when they are updated. --- src/comment.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/comment.ts b/src/comment.ts index eb3e96c..0da254a 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -19,6 +19,10 @@ function bodyWithHeader(body: string, header: string): string { return `${body}\n${headerComment(header)}` } +function bodyWithoutHeader(body: string, header: string): string { + return body.replace(`\n${headerComment(header)}`, ""); +} + export async function findPreviousComment( octokit: InstanceType, repo: { @@ -88,6 +92,9 @@ export async function updateComment( if (!body && !previousBody) return core.warning("Comment body cannot be blank") + if (previousBody) + let rawPreviousBody = bodyWithoutHeader(previousBody, header) + await octokit.graphql( ` mutation($input: UpdateIssueCommentInput!) { @@ -103,7 +110,7 @@ export async function updateComment( input: { id, body: previousBody - ? `${previousBody}\n${body}` + ? bodyWithHeader(`${rawPreviousBody}\n${body}`, header) : bodyWithHeader(body, header) } }