mirror of
https://github.com/kekxv/AiReviewPR.git
synced 2025-02-11 22:41:50 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
327c45551f | ||
|
|
ef9245d7d5 | ||
|
|
a5b330c5bf | ||
|
|
484116be5c | ||
|
|
5348ca237b |
@@ -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
17
dist/index.js
vendored
@@ -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
18
dist/utils.js
vendored
@@ -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
4
jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
||||
3854
package-lock.json
generated
3854
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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": {
|
||||
}
|
||||
}
|
||||
|
||||
19
src/index.ts
19
src/index.ts
@@ -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 {
|
||||
|
||||
18
src/utils.ts
18
src/utils.ts
@@ -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) {
|
||||
|
||||
30
test/split_message.test.ts
Normal file
30
test/split_message.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,8 @@
|
||||
"node_modules/@types"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
"node",
|
||||
"jest"
|
||||
],
|
||||
"target": "ES2020",
|
||||
// 编译目标
|
||||
@@ -30,4 +31,4 @@
|
||||
"**/*.spec.ts"
|
||||
// 排除测试文件
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user