Skip to content

Commit

Permalink
mypy_primer: truncate per-project output (#14091)
Browse files Browse the repository at this point in the history
Closes #14059
  • Loading branch information
ikonst authored Nov 18, 2022
1 parent 6d1bcc1 commit abb5a80
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/mypy_primer_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,29 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const MAX_CHARACTERS = 30000
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
const fs = require('fs')
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
// posting comment fails if too long, so truncate
if (data.length > 30000) {
let truncated_data = data.substring(0, 30000)
let lines_truncated = data.split('\n').length - truncated_data.split('\n').length
data = truncated_data + `\n\n... (truncated ${lines_truncated} lines) ...\n`
function truncateIfNeeded(original, maxLength) {
if (original.length <= maxLength) {
return original
}
let truncated = original.substring(0, maxLength)
// further, remove last line that might be truncated
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
let lines_truncated = original.split('\n').length - truncated.split('\n').length
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
}
const projects = data.split('\n\n')
// don't let one project dominate
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
// posting comment fails if too long, so truncate
data = truncateIfNeeded(data, MAX_CHARACTERS)
console.log("Diff from mypy_primer:")
console.log(data)
Expand Down

0 comments on commit abb5a80

Please sign in to comment.