Skip to content

Commit 0c0dcc2

Browse files
fix: post the summary without the queries table when the comment is too large (#170)
1 parent 12573fd commit 0c0dcc2

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/commenter.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ function computeHeaders(flattenedQueries) {
130130
return [...new Set(tmpHeader.map(v => v))]
131131
}
132132

133+
const MAX_COMMENT_LENGTH = 65536;
134+
133135
async function postPRComment(results, repo, prNumber, octokit, commentWithQueries = false, excludedColumnsForCommentsWithQueries) {
134-
const message = createComment(results, commentWithQueries, excludedColumnsForCommentsWithQueries);
136+
let message = createComment(results, commentWithQueries, excludedColumnsForCommentsWithQueries);
137+
if (message.length > MAX_COMMENT_LENGTH) {
138+
message = createComment(results) + "_The queries table was omitted: it exceeds the GitHub comment size limit._\n";
139+
}
135140

136141
const comments = await octokit.paginate(octokit.rest.issues.listComments, {
137142
...repo,

‎test/unit/commenter.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test('GitHub comment size limit', async (t) => {
129129
assert.ok(postedBody(fake).length < MAX_COMMENT_LENGTH)
130130
})
131131

132-
await t.test('a huge report with queries still gets posted', knownBug('GitHub rejects bodies over 65536 characters with 422; the report must be truncated or split'), async (t) => {
132+
await t.test('a huge report with queries still gets posted', async (t) => {
133133
const fake = await startFakeGitHub(t)
134134
const many = Array.from({ length: 400 }, (_, i) => finding({ file_name: `modules/service-${i}/main.tf`, line: i + 1 }))
135135
const results = kicsResults({ queries: [query({ files: many })] })

0 commit comments

Comments
 (0)