Skip to content

Commit

Permalink
Always move ID comment to end of message (#1362)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NoRePercussions committed Jul 17, 2024
1 parent 766e735 commit 32226fa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof GitHub>,
repo: {
Expand Down Expand Up @@ -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!) {
Expand All @@ -103,7 +110,7 @@ export async function updateComment(
input: {
id,
body: previousBody
? `${previousBody}\n${body}`
? bodyWithHeader(`${rawPreviousBody}\n${body}`, header)
: bodyWithHeader(body, header)
}
}
Expand Down

0 comments on commit 32226fa

Please sign in to comment.