Skip to content

Commit 312b609

Browse files
committed
ci: include more of the primer diff
1 parent d328c22 commit 312b609

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

.github/workflows/mypy_primer_comment.yml

+14-8
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,34 @@ jobs:
4848
with:
4949
github-token: ${{ secrets.GITHUB_TOKEN }}
5050
script: |
51-
const MAX_CHARACTERS = 30000
51+
// not really max characters, more like 'max bytes'
52+
const MAX_CHARACTERS = 262144
5253
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
5354
5455
const fs = require('fs')
5556
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
5657
58+
function bytesLength(string) {
59+
return new TextEncoder().encode(string).length
60+
}
61+
5762
function truncateIfNeeded(original, maxLength) {
58-
if (original.length <= maxLength) {
63+
const bytes = new TextEncoder().encode(original)
64+
if (bytes.length <= maxLength) {
5965
return original
6066
}
61-
let truncated = original.substring(0, maxLength)
67+
let truncated = new TextDecoder().decode(bytes.slice(0, maxLength)).replace('\uFFFD', '')
6268
// further, remove last line that might be truncated
6369
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
6470
let lines_truncated = original.split('\n').length - truncated.split('\n').length
6571
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
6672
}
6773
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)
74+
if (bytesLength(data) > maxLength) {
75+
const projects = data.split('\n\n')
76+
// don't let one project dominate
77+
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
78+
}
7379
7480
console.log("Diff from mypy_primer:")
7581
console.log(data)

0 commit comments

Comments
 (0)