fix(gitea): diff 過濾排除 node_modules 與 lock 檔,避免超出 LLM 輸入上限
This commit is contained in:
+12
-6
@@ -54,6 +54,9 @@ export async function getPRDiff() {
|
|||||||
'.github/',
|
'.github/',
|
||||||
'README.md',
|
'README.md',
|
||||||
'TODO.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/`)。
|
* @param {string[]} excludePrefixes - 要排除的路徑前綴陣列(資料夾以 `/` 結尾,如 `.gitea/`)。
|
||||||
* @returns {string} 過濾後重新接合的 diff 文字。
|
* @returns {string} 過濾後重新接合的 diff 文字。
|
||||||
*/
|
*/
|
||||||
export function filterDiff(diff, excludePrefixes) {
|
export function filterDiff(diff, excludePrefixes = []) {
|
||||||
return diff.split(/(?=^diff --git )/m)
|
return diff.split(/(?=^diff --git )/m)
|
||||||
.filter(block => !excludePrefixes.some(p => {
|
.filter(block => {
|
||||||
const prefix = `diff --git a/${p}`;
|
const m = block.match(/^diff --git a\/(.+?) b\//);
|
||||||
const singleFile = `diff --git a/${p} b/${p}`;
|
const path = m ? m[1] : '';
|
||||||
return block.startsWith(prefix) || block.startsWith(singleFile);
|
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('');
|
.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user