Skip to content

Commit b8d1849

Browse files
committed
improve truncation
1 parent d19c2d8 commit b8d1849

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

.github/workflows/mypy_primer_comment.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ jobs:
5454
const fs = require('fs')
5555
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
5656
57-
function truncateIfNeeded(s, maxLength) {
58-
let truncated = s.substring(0, maxLength)
59-
if (s.length === truncated.length) {
60-
return s
57+
function truncateIfNeeded(original, maxLength) {
58+
let truncated = original.substring(0, maxLength)
59+
if (original.length === truncated.length) {
60+
return original
6161
}
62-
let lines_truncated = s.split('\n').length - truncated.split('\n').length
63-
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...\n`
62+
// further, remove last line that might be truncated
63+
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
64+
let lines_truncated = original.split('\n').length - truncated.split('\n').length
65+
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
6466
}
6567
6668
const projects = data.split('\n\n')

0 commit comments

Comments
 (0)