Skip to content

Commit

Permalink
fix: truncate long comment bodies during comment update too (#205)
Browse files Browse the repository at this point in the history
* Truncate long bodies during comment update too

* Fix code formatting
  • Loading branch information
Dermah committed Jun 8, 2023
1 parent 5825e57 commit ce3fa35
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/create-or-update-comment.ts
Expand Up @@ -118,18 +118,23 @@ 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,
repo: string,
issueNumber: number,
body: string
): Promise<number> {
// 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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ce3fa35

Please sign in to comment.