gitlab-ai-review 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +65 -0
- package/package.json +4 -10
package/lib/config.js
CHANGED
|
@@ -3,6 +3,53 @@
|
|
|
3
3
|
* 参考 review-bot/config.js 的实现
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 读取项目根目录下的 AI Review Guard 配置文件
|
|
11
|
+
*/
|
|
12
|
+
function readAIReviewGuardConfig() {
|
|
13
|
+
const configFiles = ['.aireviewguard', 'aireviewguard', '.aireviewguard.json', 'reviewguard.md', '.reviewguard.md'];
|
|
14
|
+
|
|
15
|
+
for (const filename of configFiles) {
|
|
16
|
+
try {
|
|
17
|
+
const configPath = path.join(process.cwd(), filename);
|
|
18
|
+
if (fs.existsSync(configPath)) {
|
|
19
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
20
|
+
|
|
21
|
+
// 如果是 Markdown 文件,返回原始内容
|
|
22
|
+
if (filename.endsWith('.md')) {
|
|
23
|
+
return {
|
|
24
|
+
type: 'markdown',
|
|
25
|
+
filename,
|
|
26
|
+
content,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 尝试解析 JSON,如果失败则返回纯文本
|
|
31
|
+
try {
|
|
32
|
+
return {
|
|
33
|
+
type: 'json',
|
|
34
|
+
filename,
|
|
35
|
+
...JSON.parse(content),
|
|
36
|
+
};
|
|
37
|
+
} catch {
|
|
38
|
+
return {
|
|
39
|
+
type: 'text',
|
|
40
|
+
filename,
|
|
41
|
+
content,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
// 忽略读取错误,继续尝试下一个文件
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
6
53
|
/**
|
|
7
54
|
* 获取 GitLab 配置(支持自动检测 CI 环境)
|
|
8
55
|
*/
|
|
@@ -26,6 +73,22 @@ export function getGitLabConfig() {
|
|
|
26
73
|
return { token, url };
|
|
27
74
|
}
|
|
28
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 获取 AI 配置(ARK API Key)
|
|
78
|
+
*/
|
|
79
|
+
export function getAIConfig() {
|
|
80
|
+
// 从环境变量读取 ARK_API_KEY
|
|
81
|
+
const arkApiKey = process.env.ARK_API_KEY || '';
|
|
82
|
+
|
|
83
|
+
// 从配置文件读取其他配置
|
|
84
|
+
const guardConfig = readAIReviewGuardConfig();
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
arkApiKey,
|
|
88
|
+
guardConfig,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
29
92
|
/**
|
|
30
93
|
* 获取项目配置(支持自动检测 CI 环境)
|
|
31
94
|
*/
|
|
@@ -55,10 +118,12 @@ export function getProjectConfig() {
|
|
|
55
118
|
export function getConfig() {
|
|
56
119
|
const gitlab = getGitLabConfig();
|
|
57
120
|
const project = getProjectConfig();
|
|
121
|
+
const ai = getAIConfig();
|
|
58
122
|
|
|
59
123
|
return {
|
|
60
124
|
gitlab,
|
|
61
125
|
project,
|
|
126
|
+
ai,
|
|
62
127
|
};
|
|
63
128
|
}
|
|
64
129
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitlab-ai-review",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "GitLab AI Review SDK - 支持 CI/CD
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "GitLab AI Review SDK - 支持 CI/CD 自动配置和 ARK API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
@@ -19,16 +19,10 @@
|
|
|
19
19
|
"ai",
|
|
20
20
|
"review",
|
|
21
21
|
"sdk",
|
|
22
|
-
"ci-cd"
|
|
23
|
-
"code-review",
|
|
24
|
-
"automation"
|
|
22
|
+
"ci-cd"
|
|
25
23
|
],
|
|
26
|
-
"author": "
|
|
24
|
+
"author": "",
|
|
27
25
|
"license": "MIT",
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "https://ksogitlab.wps.kingsoft.net/web_training/web-professional-25-tasks/dengjiang1"
|
|
31
|
-
},
|
|
32
26
|
"engines": {
|
|
33
27
|
"node": ">=18.0.0"
|
|
34
28
|
}
|