Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always move ID comment to end of message #1373

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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