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

Truncate long comment bodies during comment update too #205

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/create-or-update-comment.ts
Original file line number Diff line number Diff line change
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)
}
peter-evans marked this conversation as resolved.
Show resolved Hide resolved
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