@@ -48,28 +48,34 @@ jobs:
48
48
with :
49
49
github-token : ${{ secrets.GITHUB_TOKEN }}
50
50
script : |
51
- const MAX_CHARACTERS = 30000
51
+ // not really max characters, more like 'max bytes'
52
+ const MAX_CHARACTERS = 262144
52
53
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
53
54
54
55
const fs = require('fs')
55
56
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
56
57
58
+ function bytesLength(string) {
59
+ return new TextEncoder().encode(string).length
60
+ }
61
+
57
62
function truncateIfNeeded(original, maxLength) {
58
- if (original.length <= maxLength) {
63
+ const bytes = new TextEncoder().encode(original)
64
+ if (bytes.length <= maxLength) {
59
65
return original
60
66
}
61
- let truncated = original.substring( 0, maxLength)
67
+ let truncated = new TextDecoder().decode(bytes.slice( 0, maxLength)).replace('\uFFFD', '' )
62
68
// further, remove last line that might be truncated
63
69
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
64
70
let lines_truncated = original.split('\n').length - truncated.split('\n').length
65
71
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
66
72
}
67
73
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
+ }
73
79
74
80
console.log("Diff from mypy_primer:")
75
81
console.log(data)
0 commit comments