From ce3fa353c4b456c533f86e14c3343f301d2fe5ed Mon Sep 17 00:00:00 2001 From: Sputnik Date: Thu, 8 Jun 2023 08:52:37 +0200 Subject: [PATCH] fix: truncate long comment bodies during comment update too (#205) * Truncate long bodies during comment update too * Fix code formatting --- src/create-or-update-comment.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/create-or-update-comment.ts b/src/create-or-update-comment.ts index 287952f..80880ad 100644 --- a/src/create-or-update-comment.ts +++ b/src/create-or-update-comment.ts @@ -118,6 +118,15 @@ function appendSeparatorTo(body: string, separator: string): string { } } +function truncateBody(body: string) { + // 65536 characters is the maximum allowed for issue comments. + if (body.length > 65536) { + core.warning(`Comment body is too long. Truncating to 65536 characters.`) + return body.substring(0, 65536) + } + return body +} + async function createComment( octokit, owner: string, @@ -125,11 +134,7 @@ async function createComment( issueNumber: number, body: string ): Promise { - // 65536 characters is the maximum allowed for issue comments. - if (body.length > 65536) { - core.warning(`Comment body is too long. Truncating to 65536 characters.`) - body = body.substring(0, 65536) - } + body = truncateBody(body) const {data: comment} = await octokit.rest.issues.createComment({ owner: owner, @@ -164,7 +169,7 @@ async function updateComment( appendSeparator ) } - commentBody = commentBody + body + commentBody = truncateBody(commentBody + body) core.debug(`Comment body: ${commentBody}`) await octokit.rest.issues.updateComment({ owner: owner,