Skip to content

Commit

Permalink
Add truncate warning to body of comment (#272)
Browse files Browse the repository at this point in the history
* Add truncate warning to body of comment (#271)

* add truncate warning to body of comment

* tweak warning

Co-authored-by: Peter Evans <18365890+peter-evans@users.noreply.github.com>

---------

Co-authored-by: Peter Evans <18365890+peter-evans@users.noreply.github.com>

* lint fixes

* update dist

---------

Co-authored-by: Ethan Davidson <ethanmdavidson@gmail.com>
  • Loading branch information
peter-evans and ethanmdavidson committed Oct 19, 2023
1 parent d85800f commit 23ff157
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dist/index.js
Expand Up @@ -130,9 +130,10 @@ function appendSeparatorTo(body, separator) {
}
function truncateBody(body) {
// 65536 characters is the maximum allowed for issue comments.
const truncateWarning = '...*[Comment body truncated]*';
if (body.length > 65536) {
core.warning(`Comment body is too long. Truncating to 65536 characters.`);
return body.substring(0, 65536);
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning;
}
return body;
}
Expand Down
3 changes: 2 additions & 1 deletion src/create-or-update-comment.ts
Expand Up @@ -120,9 +120,10 @@ function appendSeparatorTo(body: string, separator: string): string {

function truncateBody(body: string) {
// 65536 characters is the maximum allowed for issue comments.
const truncateWarning = '...*[Comment body truncated]*'
if (body.length > 65536) {
core.warning(`Comment body is too long. Truncating to 65536 characters.`)
return body.substring(0, 65536)
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning
}
return body
}
Expand Down

0 comments on commit 23ff157

Please sign in to comment.