Skip to content

Commit ce3fa35

Browse files
authored
fix: truncate long comment bodies during comment update too (#205)
* Truncate long bodies during comment update too * Fix code formatting
1 parent 5825e57 commit ce3fa35

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/create-or-update-comment.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,23 @@ function appendSeparatorTo(body: string, separator: string): string {
118118
}
119119
}
120120

121+
function truncateBody(body: string) {
122+
// 65536 characters is the maximum allowed for issue comments.
123+
if (body.length > 65536) {
124+
core.warning(`Comment body is too long. Truncating to 65536 characters.`)
125+
return body.substring(0, 65536)
126+
}
127+
return body
128+
}
129+
121130
async function createComment(
122131
octokit,
123132
owner: string,
124133
repo: string,
125134
issueNumber: number,
126135
body: string
127136
): Promise<number> {
128-
// 65536 characters is the maximum allowed for issue comments.
129-
if (body.length > 65536) {
130-
core.warning(`Comment body is too long. Truncating to 65536 characters.`)
131-
body = body.substring(0, 65536)
132-
}
137+
body = truncateBody(body)
133138

134139
const {data: comment} = await octokit.rest.issues.createComment({
135140
owner: owner,
@@ -164,7 +169,7 @@ async function updateComment(
164169
appendSeparator
165170
)
166171
}
167-
commentBody = commentBody + body
172+
commentBody = truncateBody(commentBody + body)
168173
core.debug(`Comment body: ${commentBody}`)
169174
await octokit.rest.issues.updateComment({
170175
owner: owner,

0 commit comments

Comments
 (0)