korekt-cli 0.11.0 → 0.11.2
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/git-logic.js +16 -0
- package/src/index.js +30 -2
- package/src/index.test.js +30 -0
- package/src/utils.js +14 -6
package/package.json
CHANGED
package/src/git-logic.js
CHANGED
|
@@ -215,6 +215,14 @@ export async function runUncommittedReview(mode = 'unstaged', fileRulesConfig =
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
// Check if file count exceeds max_files_for_content limit
|
|
219
|
+
if (config.max_files_for_content && fileList.length > config.max_files_for_content) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Too many files: ${fileList.length} files exceeds the limit of ${config.max_files_for_content}. ` +
|
|
222
|
+
`Please reduce the number of changed files before reviewing.`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
218
226
|
// Check if this is a large change set (only if config has large_pr_threshold)
|
|
219
227
|
const isLargePr = config.large_pr_threshold && fileList.length > config.large_pr_threshold;
|
|
220
228
|
if (isLargePr) {
|
|
@@ -548,6 +556,14 @@ export async function runLocalReview(
|
|
|
548
556
|
}
|
|
549
557
|
}
|
|
550
558
|
|
|
559
|
+
// Check if file count exceeds max_files_for_content limit
|
|
560
|
+
if (config.max_files_for_content && filteredFileList.length > config.max_files_for_content) {
|
|
561
|
+
throw new Error(
|
|
562
|
+
`Too many files: ${filteredFileList.length} files exceeds the limit of ${config.max_files_for_content}. ` +
|
|
563
|
+
`Please split this PR into smaller reviews or use --ignore to exclude some files.`
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
551
567
|
// Check if this is a large PR (only if config has large_pr_threshold)
|
|
552
568
|
const isLargePr =
|
|
553
569
|
config.large_pr_threshold && filteredFileList.length > config.large_pr_threshold;
|
package/src/index.js
CHANGED
|
@@ -22,6 +22,28 @@ export { detectCIProvider, truncateFileData, formatErrorOutput, getPrUrl } from
|
|
|
22
22
|
const require = createRequire(import.meta.url);
|
|
23
23
|
const { version } = require('../package.json');
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Fetch file processing rules from the API.
|
|
27
|
+
* These rules control which files to skip, which to show diff-only, etc.
|
|
28
|
+
* @param {string} apiEndpoint - The API endpoint URL
|
|
29
|
+
* @param {string} apiKey - The API key for authentication
|
|
30
|
+
* @returns {Promise<Object|null>} - Config object or null if fetch fails
|
|
31
|
+
*/
|
|
32
|
+
async function fetchFileRulesConfig(apiEndpoint, apiKey) {
|
|
33
|
+
try {
|
|
34
|
+
const configEndpoint = apiEndpoint.replace(/\/review\/?$/, '/config/file-rules');
|
|
35
|
+
const response = await axios.get(configEndpoint, {
|
|
36
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
37
|
+
timeout: 3000,
|
|
38
|
+
});
|
|
39
|
+
return response.data;
|
|
40
|
+
} catch {
|
|
41
|
+
// Non-fatal: continue without filtering if config unavailable
|
|
42
|
+
log(chalk.yellow('Warning: Could not fetch file rules config.'));
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
25
47
|
/**
|
|
26
48
|
* Helper functions for clean output separation:
|
|
27
49
|
* - log() writes to stderr (progress, info, errors)
|
|
@@ -157,8 +179,11 @@ program
|
|
|
157
179
|
process.exit(1);
|
|
158
180
|
}
|
|
159
181
|
|
|
182
|
+
// Fetch file rules config from API
|
|
183
|
+
const fileRulesConfig = await fetchFileRulesConfig(apiEndpoint, apiKey);
|
|
184
|
+
|
|
160
185
|
// Gather all data using our git logic module
|
|
161
|
-
const payload = await runLocalReview(targetBranch, options.ignore);
|
|
186
|
+
const payload = await runLocalReview(targetBranch, options.ignore, fileRulesConfig);
|
|
162
187
|
|
|
163
188
|
if (!payload) {
|
|
164
189
|
log(chalk.red('Could not proceed with review due to errors during analysis.'));
|
|
@@ -334,8 +359,11 @@ async function reviewUncommitted(mode, options) {
|
|
|
334
359
|
process.exit(1);
|
|
335
360
|
}
|
|
336
361
|
|
|
362
|
+
// Fetch file rules config from API
|
|
363
|
+
const fileRulesConfig = await fetchFileRulesConfig(apiEndpoint, apiKey);
|
|
364
|
+
|
|
337
365
|
const { runUncommittedReview } = await import('./git-logic.js');
|
|
338
|
-
const payload = await runUncommittedReview(mode);
|
|
366
|
+
const payload = await runUncommittedReview(mode, fileRulesConfig);
|
|
339
367
|
|
|
340
368
|
if (!payload) {
|
|
341
369
|
log(chalk.red('No changes found or error occurred during analysis.'));
|
package/src/index.test.js
CHANGED
|
@@ -153,6 +153,36 @@ describe('CLI JSON output mode', () => {
|
|
|
153
153
|
expect(displayFile.diff).not.toContain('truncated');
|
|
154
154
|
expect(displayFile.content).not.toContain('truncated');
|
|
155
155
|
});
|
|
156
|
+
|
|
157
|
+
it('should handle diff-only files without content', () => {
|
|
158
|
+
const file = {
|
|
159
|
+
path: 'test.js',
|
|
160
|
+
status: 'M',
|
|
161
|
+
diff: 'some diff here',
|
|
162
|
+
// no content field - this is a diff-only file
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const displayFile = truncateFileData(file);
|
|
166
|
+
|
|
167
|
+
expect(displayFile.path).toBe('test.js');
|
|
168
|
+
expect(displayFile.status).toBe('M');
|
|
169
|
+
expect(displayFile.diff).toBe('some diff here');
|
|
170
|
+
expect(displayFile.content).toBeUndefined();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should handle files with neither diff nor content', () => {
|
|
174
|
+
const file = {
|
|
175
|
+
path: 'deleted.js',
|
|
176
|
+
status: 'D',
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const displayFile = truncateFileData(file);
|
|
180
|
+
|
|
181
|
+
expect(displayFile.path).toBe('deleted.js');
|
|
182
|
+
expect(displayFile.status).toBe('D');
|
|
183
|
+
expect(displayFile.diff).toBeUndefined();
|
|
184
|
+
expect(displayFile.content).toBeUndefined();
|
|
185
|
+
});
|
|
156
186
|
});
|
|
157
187
|
|
|
158
188
|
describe('error formatting for JSON mode', () => {
|
package/src/utils.js
CHANGED
|
@@ -73,19 +73,27 @@ export function getPrUrl() {
|
|
|
73
73
|
* @returns {Object} File object with truncated diff and content
|
|
74
74
|
*/
|
|
75
75
|
export function truncateFileData(file, maxLength = 500) {
|
|
76
|
-
|
|
76
|
+
const result = {
|
|
77
77
|
path: file.path,
|
|
78
78
|
status: file.status,
|
|
79
79
|
...(file.old_path && { old_path: file.old_path }),
|
|
80
|
-
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (file.diff) {
|
|
83
|
+
result.diff =
|
|
81
84
|
file.diff.length > maxLength
|
|
82
85
|
? `${file.diff.substring(0, maxLength)}... [truncated ${file.diff.length - maxLength} chars]`
|
|
83
|
-
: file.diff
|
|
84
|
-
|
|
86
|
+
: file.diff;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (file.content) {
|
|
90
|
+
result.content =
|
|
85
91
|
file.content.length > maxLength
|
|
86
92
|
? `${file.content.substring(0, maxLength)}... [truncated ${file.content.length - maxLength} chars]`
|
|
87
|
-
: file.content
|
|
88
|
-
}
|
|
93
|
+
: file.content;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
/**
|