Skip to content

Commit 149ec36

Browse files
committed
improve the truncate logic by adding logs
1 parent 225a62d commit 149ec36

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

dist/index.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/truncate-comment-body.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as core from '@actions/core'
2+
import {COLORS} from './colors'
3+
14
const truncatedMessageStart =
25
'The message is too large to be posted as a comment.\n<details><summary>Click to see the truncated message</summary>\n'
36
const truncatedMessageEnd = '\n</details>'
@@ -9,12 +12,22 @@ const maxCommentLength = 65536
912
// returned as is.
1013
// :param message: The message to be truncated (String)
1114
export function truncateCommentBody(message) {
15+
// If the message is short enough, return it as is
1216
if (message.length <= maxCommentLength) {
17+
core.debug('comment body is within length limit')
1318
return message
1419
}
20+
21+
// if we make it here, the message is too long, so truncate it
22+
core.warning(
23+
`✂️ truncating - comment body is too long - current: ${COLORS.highlight}${message.length}${COLORS.reset} characters - max: ${COLORS.highlight}${maxCommentLength}${COLORS.reset} characters`
24+
)
25+
1526
let truncated = message.substring(
1627
0,
1728
maxCommentLength - truncatedMessageStart.length - truncatedMessageEnd.length
1829
)
30+
31+
// return the truncated message wrapped in a details tag
1932
return truncatedMessageStart + truncated + truncatedMessageEnd
2033
}

0 commit comments

Comments
 (0)