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:
|
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
17
dist/index.js
vendored
@@ -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
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 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
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"
|
"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": {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/index.ts
19
src/index.ts
@@ -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 {
|
||||||
|
|||||||
18
src/utils.ts
18
src/utils.ts
@@ -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) {
|
||||||
|
|||||||
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"
|
"node_modules/@types"
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
"node"
|
"node",
|
||||||
|
"jest"
|
||||||
],
|
],
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
// 编译目标
|
// 编译目标
|
||||||
@@ -30,4 +31,4 @@
|
|||||||
"**/*.spec.ts"
|
"**/*.spec.ts"
|
||||||
// 排除测试文件
|
// 排除测试文件
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user