mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-01-31 11:46: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(
|
async function createComment(
|
||||||
octokit,
|
octokit,
|
||||||
owner: string,
|
owner: string,
|
||||||
@ -125,11 +134,7 @@ async function createComment(
|
|||||||
issueNumber: number,
|
issueNumber: number,
|
||||||
body: string
|
body: string
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
// 65536 characters is the maximum allowed for issue comments.
|
body = truncateBody(body)
|
||||||
if (body.length > 65536) {
|
|
||||||
core.warning(`Comment body is too long. Truncating to 65536 characters.`)
|
|
||||||
body = body.substring(0, 65536)
|
|
||||||
}
|
|
||||||
|
|
||||||
const {data: comment} = await octokit.rest.issues.createComment({
|
const {data: comment} = await octokit.rest.issues.createComment({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
@ -164,7 +169,7 @@ async function updateComment(
|
|||||||
appendSeparator
|
appendSeparator
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
commentBody = commentBody + body
|
commentBody = truncateBody(commentBody + body)
|
||||||
core.debug(`Comment body: ${commentBody}`)
|
core.debug(`Comment body: ${commentBody}`)
|
||||||
await octokit.rest.issues.updateComment({
|
await octokit.rest.issues.updateComment({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user