codeant-cli 0.4.10 → 0.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/reviewApiHelper.js +38 -31
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { minimatch } from 'minimatch';
|
|
5
5
|
|
|
6
|
-
const MAX_REVIEW_FILES =
|
|
6
|
+
const MAX_REVIEW_FILES = 15;
|
|
7
7
|
const MAX_FILE_LINES = 5000;
|
|
8
8
|
const MAX_FILE_SIZE_BYTES = 200 * 1024; // 200 KB
|
|
9
9
|
|
|
@@ -184,41 +184,20 @@ class ReviewApiHelper extends CommonApiHelper {
|
|
|
184
184
|
return true;
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
-
// Dedupe by filename, keeping all hunks
|
|
187
|
+
// Dedupe by filename, keeping all hunks (no cap yet — applied after size filtering)
|
|
188
188
|
const fileOrder = [];
|
|
189
189
|
const fileHunks = new Map();
|
|
190
|
-
let capped = false;
|
|
191
190
|
for (const d of reviewable) {
|
|
192
191
|
const f = d.filename_str;
|
|
193
192
|
if (!fileHunks.has(f)) {
|
|
194
|
-
if (fileOrder.length >= MAX_REVIEW_FILES) {
|
|
195
|
-
capped = true;
|
|
196
|
-
if (!seenSkipped.has(f)) {
|
|
197
|
-
dedupedSkipped.push({ file: f, reason: `exceeded ${MAX_REVIEW_FILES}-file limit` });
|
|
198
|
-
seenSkipped.add(f);
|
|
199
|
-
}
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
193
|
fileOrder.push(f);
|
|
203
194
|
fileHunks.set(f, []);
|
|
204
195
|
}
|
|
205
196
|
fileHunks.get(f).push(d);
|
|
206
197
|
}
|
|
207
198
|
|
|
208
|
-
// Reconstruct a combined diff string from the filtered hunks
|
|
209
|
-
const parts = [];
|
|
210
|
-
for (const f of fileOrder) {
|
|
211
|
-
const hunks = fileHunks.get(f);
|
|
212
|
-
// Build a file-level diff header + all hunk patches
|
|
213
|
-
const header = `diff --git a/${f} b/${f}\n--- a/${f}\n+++ b/${f}`;
|
|
214
|
-
const hunkPatches = hunks.map(h => h.patch_str).filter(Boolean);
|
|
215
|
-
if (hunkPatches.length > 0) {
|
|
216
|
-
parts.push(header + '\n' + hunkPatches.join('\n'));
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
199
|
// Use head_file_str from diffs so file content matches the diff version (avoids working tree mismatch for --last-commit etc.)
|
|
221
|
-
|
|
200
|
+
// Filter out files that exceed size or line limits before applying the cap
|
|
222
201
|
const skippedLargeFiles = new Set();
|
|
223
202
|
for (const f of fileOrder) {
|
|
224
203
|
const hunks = fileHunks.get(f);
|
|
@@ -234,21 +213,49 @@ class ReviewApiHelper extends CommonApiHelper {
|
|
|
234
213
|
if (lineCount > MAX_FILE_LINES) {
|
|
235
214
|
skippedLargeFiles.add(f);
|
|
236
215
|
dedupedSkipped.push({ file: f, reason: `too large (${lineCount} lines, max ${MAX_FILE_LINES})` });
|
|
237
|
-
continue;
|
|
238
216
|
}
|
|
239
|
-
fileContents[f] = content;
|
|
240
217
|
}
|
|
241
218
|
}
|
|
242
219
|
|
|
243
|
-
//
|
|
244
|
-
|
|
220
|
+
// Apply MAX_REVIEW_FILES cap after all filtering (binary, deleted, pattern, size)
|
|
221
|
+
let capped = false;
|
|
222
|
+
const cappedFileOrder = [];
|
|
223
|
+
for (const f of fileOrder) {
|
|
224
|
+
if (skippedLargeFiles.has(f)) continue;
|
|
225
|
+
if (cappedFileOrder.length >= MAX_REVIEW_FILES) {
|
|
226
|
+
capped = true;
|
|
227
|
+
if (!seenSkipped.has(f)) {
|
|
228
|
+
dedupedSkipped.push({ file: f, reason: `exceeded ${MAX_REVIEW_FILES}-file limit` });
|
|
229
|
+
seenSkipped.add(f);
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
cappedFileOrder.push(f);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Build file contents for the capped set
|
|
237
|
+
const fileContents = {};
|
|
238
|
+
for (const f of cappedFileOrder) {
|
|
239
|
+
const content = fileHunks.get(f)[0]?.head_file_str || '';
|
|
240
|
+
if (content) fileContents[f] = content;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Reconstruct a combined diff string from the capped set
|
|
244
|
+
const parts = [];
|
|
245
|
+
for (const f of cappedFileOrder) {
|
|
246
|
+
const hunks = fileHunks.get(f);
|
|
247
|
+
const header = `diff --git a/${f} b/${f}\n--- a/${f}\n+++ b/${f}`;
|
|
248
|
+
const hunkPatches = hunks.map(h => h.patch_str).filter(Boolean);
|
|
249
|
+
if (hunkPatches.length > 0) {
|
|
250
|
+
parts.push(header + '\n' + hunkPatches.join('\n'));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
245
253
|
|
|
246
|
-
const reviewedFiles = fileOrder.filter(f => !skippedLargeFiles.has(f));
|
|
247
254
|
return {
|
|
248
|
-
diff_content:
|
|
255
|
+
diff_content: parts.join('\n'),
|
|
249
256
|
file_contents: fileContents,
|
|
250
257
|
_meta: {
|
|
251
|
-
reviewed_files:
|
|
258
|
+
reviewed_files: cappedFileOrder,
|
|
252
259
|
total_changed: allUniqueFiles.size,
|
|
253
260
|
skipped: dedupedSkipped,
|
|
254
261
|
capped,
|