Skip to content

Commit df33ecd

Browse files
committed
primer: big mode
1 parent a10057c commit df33ecd

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

.github/workflows/mypy_primer_comment.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,41 @@ jobs:
4848
with:
4949
github-token: ${{ secrets.GITHUB_TOKEN }}
5050
script: |
51-
const MAX_CHARACTERS = 30000
51+
const MAX_CHARACTERS = 261544
5252
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
5353
5454
const fs = require('fs')
5555
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
5656
57-
function truncateIfNeeded(original, maxLength) {
57+
function truncateIfNeeded(original, maxLength, suffix='') {
58+
maxLength -= suffix.length
5859
if (original.length <= maxLength) {
59-
return original
60+
return original + suffix
6061
}
62+
suffix += '\n\n... (truncated {lines_truncated} lines) ...'
6163
let truncated = original.substring(0, maxLength)
6264
// further, remove last line that might be truncated
6365
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
6466
let lines_truncated = original.split('\n').length - truncated.split('\n').length
65-
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
67+
return `${truncated}${suffix.replace("{lines_truncated}", lines_truncated)}`
6668
}
6769
68-
const projects = data.split('\n\n')
69-
// don't let one project dominate
70-
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
71-
// posting comment fails if too long, so truncate
72-
data = truncateIfNeeded(data, MAX_CHARACTERS)
73-
70+
if (data.length >= MAX_CHARACTERS) {
71+
const projects = data.split('\n\n')
72+
// don't let one project dominate
73+
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
74+
}
7475
console.log("Diff from mypy_primer:")
7576
console.log(data)
7677
7778
let body
7879
if (data.trim()) {
79-
body = 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
80+
data = '```diff\n' + data
81+
if (data.split('\n').length > 500) {
82+
data = '<details><summary></summary>\n\n' + data + '```'
83+
}
84+
body = 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n' + data
85+
body = truncateIfNeeded(body, MAX_CHARACTERS, data.split('\n').length > 500 ? '```</details>' : '')
8086
} else {
8187
body = 'According to [mypy_primer](https://github.com/hauntsaninja/mypy_primer), this change has no effect on the checked open source code. 🤖🎉'
8288
}

0 commit comments

Comments
 (0)