Skip to content

Commit c1c2e05

Browse files
committed
mypy_primer: truncate per-project output
1 parent dd0503e commit c1c2e05

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

.github/workflows/mypy_primer_comment.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,27 @@ jobs:
4848
with:
4949
github-token: ${{ secrets.GITHUB_TOKEN }}
5050
script: |
51+
const MAX_CHARACTERS = 30000
52+
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
53+
5154
const fs = require('fs')
5255
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
53-
// posting comment fails if too long, so truncate
54-
if (data.length > 30000) {
55-
let truncated_data = data.substring(0, 30000)
56-
let lines_truncated = data.split('\n').length - truncated_data.split('\n').length
57-
data = truncated_data + `\n\n... (truncated ${lines_truncated} lines) ...\n`
56+
57+
function truncateIfNeeded(s, maxLength) {
58+
let truncated = s.substring(0, maxLength)
59+
if (s.length === truncated.length) {
60+
return s
61+
}
62+
let lines_truncated = s.split('\n').length - truncated.split('\n').length
63+
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...\n`
5864
}
5965
66+
const projects = data.split('\n\n')
67+
// don't let one project dominate
68+
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
69+
// posting comment fails if too long, so truncate
70+
data = truncateIfNeeded(data, MAX_CHARACTERS)
71+
6072
console.log("Diff from mypy_primer:")
6173
console.log(data)
6274

0 commit comments

Comments
 (0)