Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3393e43877 | ||
|
|
6868dbdc8f |
+12
-6
@@ -54,6 +54,9 @@ export async function getPRDiff() {
|
||||
'.github/',
|
||||
'README.md',
|
||||
'TODO.md',
|
||||
'package-lock.json',
|
||||
'src/package-lock.json',
|
||||
'dist/',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -126,13 +129,16 @@ export async function shouldSkipBotCommit({ sha = PR_HEAD_SHA || process.env.GIT
|
||||
* @param {string[]} excludePrefixes - 要排除的路徑前綴陣列(資料夾以 `/` 結尾,如 `.gitea/`)。
|
||||
* @returns {string} 過濾後重新接合的 diff 文字。
|
||||
*/
|
||||
export function filterDiff(diff, excludePrefixes) {
|
||||
export function filterDiff(diff, excludePrefixes = []) {
|
||||
return diff.split(/(?=^diff --git )/m)
|
||||
.filter(block => !excludePrefixes.some(p => {
|
||||
const prefix = `diff --git a/${p}`;
|
||||
const singleFile = `diff --git a/${p} b/${p}`;
|
||||
return block.startsWith(prefix) || block.startsWith(singleFile);
|
||||
}))
|
||||
.filter(block => {
|
||||
const m = block.match(/^diff --git a\/(.+?) b\//);
|
||||
const path = m ? m[1] : '';
|
||||
if (!path) return true;
|
||||
// 一律排除任何深度的 node_modules:vendored 依賴不是審查對象,且會撐爆 LLM 輸入上限。
|
||||
if (/(^|\/)node_modules\//.test(path)) return false;
|
||||
return !excludePrefixes.some(p => path === p || path.startsWith(p));
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
|
||||
@@ -241,4 +241,21 @@ describe('filterDiff', () => {
|
||||
it('returns empty string for empty diff', () => {
|
||||
assert.equal(filterDiff('', ['.gitea/']), '');
|
||||
});
|
||||
|
||||
it('always drops node_modules blocks at any depth (avoids blowing the LLM input limit)', () => {
|
||||
const diff = block('src/node_modules/axios/index.js')
|
||||
+ block('node_modules/js-yaml/lib.js')
|
||||
+ block('src/main.js');
|
||||
const result = filterDiff(diff, []);
|
||||
assert.ok(!result.includes('node_modules'));
|
||||
assert.ok(result.includes('src/main.js'));
|
||||
});
|
||||
|
||||
it('excludes lock files and dist via the getPRDiff prefix list', () => {
|
||||
const diff = block('src/package-lock.json') + block('dist/index.js') + block('src/main.js');
|
||||
const result = filterDiff(diff, ['package-lock.json', 'src/package-lock.json', 'dist/']);
|
||||
assert.ok(!result.includes('package-lock.json'));
|
||||
assert.ok(!result.includes('dist/'));
|
||||
assert.ok(result.includes('src/main.js'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user