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

17
dist/index.js vendored
View File

@@ -59,17 +59,14 @@ async function aiCheckDiffContext() {
for (let key in files) {
if (!files[key])
continue;
if (include_files.length > 0) {
if (!(0, utils_1.doesAnyPatternMatch)(include_files, files[key])) {
console.log("exclude(include):", files[key]);
continue;
}
console.log("check diff context:", files[key]);
if ((include_files.length > 0) && (!(0, utils_1.doesAnyPatternMatch)(include_files, files[key]))) {
console.log("exclude(include):", files[key]);
continue;
}
if (exclude_files.length > 0) {
if ((0, utils_1.doesAnyPatternMatch)(exclude_files, files[key])) {
console.log("exclude(exclude):", files[key]);
continue;
}
else if ((exclude_files.length > 0) && ((0, utils_1.doesAnyPatternMatch)(exclude_files, files[key]))) {
console.log("exclude(exclude):", files[key]);
continue;
}
const fileDiffOutput = (0, node_child_process_1.execSync)(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, { encoding: 'utf-8' });
// 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 https_1 = __importDefault(require("https"));
function split_message(files) {
console.log("files debug:", files);
files = files || "";
let n = files.includes('\n') || files.includes('\r');
files = files.trim();
if (!files) {
let t = files.split("\n");
if (t.length > 0)
return t.map(str => str.trim());
return files.split(",").map(str => str.trim());
let res = [];
if (files) {
if (n) {
res = files.split(/[\r\n]/);
}
else {
res = files.split(",");
}
}
return [];
return res.map(str => str.trim()).filter(item => item !== null && item !== undefined && item !== "");
}
exports.split_message = split_message;
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"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.6",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"typescript": "^4.5.4"
},
"dependencies": {
}
}

View File

@@ -63,18 +63,15 @@ async function aiCheckDiffContext() {
let files = diffOutput.trim().split("\n");
for (let key in files) {
if (!files[key]) continue;
if (include_files.length > 0) {
if (!doesAnyPatternMatch(include_files, files[key])) {
console.log("exclude(include):", files[key])
continue;
}
}
if (exclude_files.length > 0) {
if (doesAnyPatternMatch(exclude_files, files[key])) {
console.log("exclude(exclude):", files[key])
continue;
}
console.log("check diff context:", files[key])
if ((include_files.length > 0) && (!doesAnyPatternMatch(include_files, files[key]))) {
console.log("exclude(include):", files[key])
continue;
} else if ((exclude_files.length > 0) && (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'});
// ai generate
try {

View File

@@ -1,15 +1,19 @@
import http from "http";
import https from "https";
export function split_message(files: string) {
console.log("files debug:",files)
export function split_message(files: string): string[] {
files = files || "";
let n = files.includes('\n') || files.includes('\r');
files = files.trim()
if (!files) {
let t = files.split("\n");
if (t.length > 0) return t.map(str => str.trim());
return files.split(",").map(str => str.trim())
let res: string[] = [];
if (files) {
if (n) {
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) {

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"
],
"types": [
"node"
"node",
"jest"
],
"target": "ES2020",
// 编译目标
@@ -30,4 +31,4 @@
"**/*.spec.ts"
// 排除测试文件
]
}
}