mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-01-18 19:22:44 +08:00
fix: truncate long comment bodies during comment update too (#205)
* Truncate long bodies during comment update too * Fix code formatting
This commit is contained in:
parent
5825e577e3
commit
ce3fa353c4
@ -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<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,
|
||||
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user