5 Commits

Author SHA1 Message Date
caesar
327c45551f update doc 2025-01-16 09:25:48 +08:00
caesar
ef9245d7d5 update doc 2025-01-16 09:25:24 +08:00
caesar
a5b330c5bf fix include exclude 2025-01-16 09:20:36 +08:00
caesar
484116be5c fix 2025-01-16 09:06:11 +08:00
caesar
5348ca237b fix 2025-01-15 22:38:01 +08:00
10 changed files with 3865 additions and 114 deletions

View File

@@ -43,11 +43,14 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Review code - name: Review code
uses: kekxv/AiReviewPR@v0.0.1 uses: kekxv/AiReviewPR@v0.0.2
with: with:
model: 'gemma2:2b' model: 'gemma2:2b'
host: ${{ vars.OLLAMA_HOST }} host: ${{ vars.OLLAMA_HOST }}
ai_token: ${{ secrets.AI_TOKEN }} ai_token: ${{ secrets.AI_TOKEN }}
exclude_files: |
^.+\.md
test2\.js
``` ```
效果如下: 效果如下:
@@ -106,12 +109,12 @@ result
- **默认值**: `" "` - **默认值**: `" "`
10. **include_files**: 10. **include_files**:
- **描述**: 要包含审查的文件列表,以逗号分隔。 - **描述**: 要包含审查的文件列表,以逗号分隔,支持换行
- **必需**: 否 - **必需**: 否
- **默认值**: `" "`(默认为空,不限制) - **默认值**: `" "`(默认为空,不限制)
11. **exclude_files**: 11. **exclude_files**:
- **描述**: 要排除审查的文件列表,以逗号分隔。 - **描述**: 要排除审查的文件列表,以逗号分隔,支持换行
- **必需**: 否 - **必需**: 否
- **默认值**: `" "`(默认为空,不传递文件) - **默认值**: `" "`(默认为空,不传递文件)

17
dist/index.js vendored
View File

@@ -59,17 +59,14 @@ async function aiCheckDiffContext() {
for (let key in files) { for (let key in files) {
if (!files[key]) if (!files[key])
continue; continue;
if (include_files.length > 0) { console.log("check diff context:", files[key]);
if (!(0, utils_1.doesAnyPatternMatch)(include_files, files[key])) { if ((include_files.length > 0) && (!(0, utils_1.doesAnyPatternMatch)(include_files, files[key]))) {
console.log("exclude(include):", files[key]); console.log("exclude(include):", files[key]);
continue; continue;
}
} }
if (exclude_files.length > 0) { else if ((exclude_files.length > 0) && ((0, utils_1.doesAnyPatternMatch)(exclude_files, files[key]))) {
if ((0, utils_1.doesAnyPatternMatch)(exclude_files, files[key])) { console.log("exclude(exclude):", files[key]);
console.log("exclude(exclude):", files[key]); continue;
continue;
}
} }
const fileDiffOutput = (0, node_child_process_1.execSync)(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, { encoding: 'utf-8' }); const fileDiffOutput = (0, node_child_process_1.execSync)(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, { encoding: 'utf-8' });
// ai generate // ai generate

18
dist/utils.js vendored
View File

@@ -7,15 +7,19 @@ exports.post = exports.doesAnyPatternMatch = exports.split_message = void 0;
const http_1 = __importDefault(require("http")); const http_1 = __importDefault(require("http"));
const https_1 = __importDefault(require("https")); const https_1 = __importDefault(require("https"));
function split_message(files) { function split_message(files) {
console.log("files debug:", files); files = files || "";
let n = files.includes('\n') || files.includes('\r');
files = files.trim(); files = files.trim();
if (!files) { let res = [];
let t = files.split("\n"); if (files) {
if (t.length > 0) if (n) {
return t.map(str => str.trim()); res = files.split(/[\r\n]/);
return files.split(",").map(str => str.trim()); }
else {
res = files.split(",");
}
} }
return []; return res.map(str => str.trim()).filter(item => item !== null && item !== undefined && item !== "");
} }
exports.split_message = split_message; exports.split_message = split_message;
function doesAnyPatternMatch(patterns, str) { function doesAnyPatternMatch(patterns, str) {

4
jest.config.js Normal file
View File

@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

3854
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,9 +6,10 @@
"build": "tsc" "build": "tsc"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.6", "@types/node": "^22.10.6",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"typescript": "^4.5.4" "typescript": "^4.5.4"
},
"dependencies": {
} }
} }

View File

@@ -63,18 +63,15 @@ async function aiCheckDiffContext() {
let files = diffOutput.trim().split("\n"); let files = diffOutput.trim().split("\n");
for (let key in files) { for (let key in files) {
if (!files[key]) continue; if (!files[key]) continue;
if (include_files.length > 0) { console.log("check diff context:", files[key])
if (!doesAnyPatternMatch(include_files, files[key])) { if ((include_files.length > 0) && (!doesAnyPatternMatch(include_files, files[key]))) {
console.log("exclude(include):", files[key]) console.log("exclude(include):", files[key])
continue; continue;
} } else if ((exclude_files.length > 0) && (doesAnyPatternMatch(exclude_files, files[key]))) {
} console.log("exclude(exclude):", files[key])
if (exclude_files.length > 0) { continue;
if (doesAnyPatternMatch(exclude_files, files[key])) {
console.log("exclude(exclude):", files[key])
continue;
}
} }
const fileDiffOutput = execSync(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, {encoding: 'utf-8'}); const fileDiffOutput = execSync(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, {encoding: 'utf-8'});
// ai generate // ai generate
try { try {

View File

@@ -1,15 +1,19 @@
import http from "http"; import http from "http";
import https from "https"; import https from "https";
export function split_message(files: string) { export function split_message(files: string): string[] {
console.log("files debug:",files) files = files || "";
let n = files.includes('\n') || files.includes('\r');
files = files.trim() files = files.trim()
if (!files) { let res: string[] = [];
let t = files.split("\n"); if (files) {
if (t.length > 0) return t.map(str => str.trim()); if (n) {
return files.split(",").map(str => str.trim()) res = files.split(/[\r\n]/);
} else {
res = files.split(",")
}
} }
return [] return res.map(str => str.trim()).filter(item => item !== null && item !== undefined && item !== "")
} }
export function doesAnyPatternMatch(patterns: Array<string>, str: string) { export function doesAnyPatternMatch(patterns: Array<string>, str: string) {

View File

@@ -0,0 +1,30 @@
// split_message.test.ts
import {doesAnyPatternMatch, split_message} from '../src/utils';
describe('split_message', () => {
it('include readme.md', () => {
const testString = `^.+\\.md
test2\\.js
dist/.*
`;
expect(doesAnyPatternMatch(split_message(testString), "readme.md")).toBe(true);
expect(doesAnyPatternMatch(split_message(testString), "dist/index.js")).toBe(true);
expect(doesAnyPatternMatch(split_message(testString), "dist/prompt.js")).toBe(true);
expect(doesAnyPatternMatch(split_message(testString), "src/index.js")).toBe(false);
});
});
describe('split_message', () => {
it('include readme.md', () => {
const testString = `^.+\\.md
test2\\.js
dist/.*
`;
let file = "README.md";
let include_files = split_message(testString);
console.log("check diff context:", file)
expect(((include_files.length > 0) && (doesAnyPatternMatch(include_files, file)))).toBe(true);
});
});

View File

@@ -5,7 +5,8 @@
"node_modules/@types" "node_modules/@types"
], ],
"types": [ "types": [
"node" "node",
"jest"
], ],
"target": "ES2020", "target": "ES2020",
// 编译目标 // 编译目标
@@ -30,4 +31,4 @@
"**/*.spec.ts" "**/*.spec.ts"
// 排除测试文件 // 排除测试文件
] ]
} }