Skip to content

Commit b9a09f2

Browse files
authored
Truncate lint output to prevent GitHub issue body size limit errors (#56409)
1 parent 24d409a commit b9a09f2

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/content-linter/scripts/post-lints.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import github from '#src/workflows/github.ts'
66
import { getEnvInputs } from '#src/workflows/get-env-inputs.ts'
77
import { createReportIssue, linkReports } from '#src/workflows/issue-report.js'
88

9+
// GitHub issue body size limit is ~65k characters, so we'll use 60k as a safe limit
10+
const MAX_ISSUE_BODY_SIZE = 60000
11+
912
// [start-readme]
1013
//
1114
// This script runs once a week via a scheduled GitHub Action to lint
@@ -45,10 +48,30 @@ async function main() {
4548

4649
core.info(`Creating issue for errors and warnings...`)
4750

51+
const parsedResults = JSON.parse(lintResults)
52+
const totalFiles = Object.keys(parsedResults).length
4853
let reportBody = 'The following files have markdown lint warnings/errors:\n\n'
49-
for (const [file, flaws] of Object.entries(JSON.parse(lintResults))) {
50-
reportBody += `File: \`${file}\`:\n`
51-
reportBody += `\`\`\`json\n${JSON.stringify(flaws, null, 2)}\n\`\`\`\n`
54+
let filesIncluded = 0
55+
let truncated = false
56+
57+
for (const [file, flaws] of Object.entries(parsedResults)) {
58+
const fileEntry = `File: \`${file}\`:\n\`\`\`json\n${JSON.stringify(flaws, null, 2)}\n\`\`\`\n`
59+
60+
// Check if adding this file would exceed the size limit
61+
if (reportBody.length + fileEntry.length > MAX_ISSUE_BODY_SIZE) {
62+
truncated = true
63+
break
64+
}
65+
66+
reportBody += fileEntry
67+
filesIncluded++
68+
}
69+
70+
// Add truncation notice if needed
71+
if (truncated) {
72+
const remaining = totalFiles - filesIncluded
73+
reportBody += `\n---\n\n⚠️ **Output truncated**: Showing ${filesIncluded} of ${totalFiles} files with lint issues. ${remaining} additional files have been omitted to stay within GitHub's issue size limits.\n`
74+
reportBody += `\nTo see all results, run the linter locally:\n\`\`\`bash\nnpm run lint-content -- --paths content data\n\`\`\`\n`
5275
}
5376

5477
const reportProps = {

0 commit comments

Comments
 (0)