gitlab-ai-review 4.2.4 → 6.3.9
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/README.md +36 -2
- package/cli.js +118 -32
- package/index.js +741 -335
- package/lib/ai-client.js +145 -61
- package/lib/config.js +798 -11
- package/lib/diff-parser.js +143 -44
- package/lib/document-loader.js +329 -0
- package/lib/export-analyzer.js +384 -0
- package/lib/gitlab-client.js +588 -7
- package/lib/prompt-tools.js +241 -453
- package/package.json +52 -50
- package/lib/impact-analyzer.js +0 -700
- package/lib/incremental-callchain-analyzer.js +0 -811
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# GitLab AI Review SDK
|
|
2
2
|
|
|
3
|
+
> ⚠️ **v5.0.0 重大变更**:已迁移至 WPS LLM Proxy API,不再支持豆包官网 ARK API。详见[版本历史](#版本历史)。
|
|
4
|
+
|
|
3
5
|
GitLab AI Review SDK - 支持 CI/CD 自动配置和手动配置
|
|
4
6
|
|
|
5
7
|
## 功能特性
|
|
@@ -20,10 +22,20 @@ GitLab AI Review SDK - 支持 CI/CD 自动配置和手动配置
|
|
|
20
22
|
- 自动跳过 Markdown 文件 (`.md`)
|
|
21
23
|
- 自动跳过配置文件 (`.json`, `.yml`, `.yaml`)
|
|
22
24
|
- 自动跳过依赖锁文件 (`package-lock.json`, `yarn.lock` 等)
|
|
23
|
-
- ✅ **AI 自动生成审核规则** 🚀
|
|
25
|
+
- ✅ **AI 自动生成审核规则** 🚀
|
|
24
26
|
- 自动分析项目技术栈和代码结构
|
|
25
27
|
- 智能生成适合项目的审核提示词
|
|
26
28
|
- 无需手动编写 `reviewguard.md` 文件
|
|
29
|
+
- ✅ **评论反馈学习机制** 🆕 NEW!
|
|
30
|
+
- 自动收集 MR 评论上的 👍/👎 表情反馈
|
|
31
|
+
- 区分正样本(好评)和负样本(差评)
|
|
32
|
+
- 审查时携带历史反馈,AI 学习优秀审查风格
|
|
33
|
+
- 数据存储在 GitLab Package Registry,不污染代码提交
|
|
34
|
+
- ✅ **项目文档上下文加载** 🆕 NEW!
|
|
35
|
+
- 自动加载项目根目录 `documents/` 文件夹下的 PRD.docx 和 TD.docx
|
|
36
|
+
- AI 自动总结产品需求文档和技术设计文档
|
|
37
|
+
- 审查时携带文档上下文,确保代码符合产品和技术设计
|
|
38
|
+
- 支持自定义文档路径
|
|
27
39
|
|
|
28
40
|
## 安装
|
|
29
41
|
|
|
@@ -322,6 +334,15 @@ npx gitlab-ai-review --max-files 5
|
|
|
322
334
|
# 限制受影响文件分析数量
|
|
323
335
|
npx gitlab-ai-review --max-affected-files 10
|
|
324
336
|
|
|
337
|
+
# 禁用项目文档加载(PRD.docx 和 TD.docx)
|
|
338
|
+
npx gitlab-ai-review --no-documents
|
|
339
|
+
|
|
340
|
+
# 自定义文档路径
|
|
341
|
+
npx gitlab-ai-review --documents-path docs
|
|
342
|
+
|
|
343
|
+
# 禁用智能补充模式
|
|
344
|
+
npx gitlab-ai-review --no-enhance
|
|
345
|
+
|
|
325
346
|
# 查看帮助
|
|
326
347
|
npx gitlab-ai-review --help
|
|
327
348
|
```
|
|
@@ -386,8 +407,21 @@ console.log('工具:', analysis.techStack.tools);
|
|
|
386
407
|
console.log('关键文件:', analysis.keyFiles.length, '个');
|
|
387
408
|
```
|
|
388
409
|
|
|
389
|
-
##
|
|
410
|
+
## 版本历史
|
|
411
|
+
|
|
412
|
+
### v5.0.0 🔄 重大变更
|
|
413
|
+
|
|
414
|
+
**⚠️ 破坏性变更:不再支持豆包官网 ARK API**
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
### v4.x 历史版本
|
|
390
423
|
|
|
424
|
+
- 4.2.4 - 支持豆包官网 ARK API(已废弃)
|
|
391
425
|
- 4.0.3 - 🚀 新增 AI 自动生成审核规则功能,支持项目结构分析
|
|
392
426
|
- 4.0.2 - 添加影响分析和智能文件过滤
|
|
393
427
|
- 1.0.1 - 添加 GitLab 客户端封装和自动配置
|
package/cli.js
CHANGED
|
@@ -11,22 +11,37 @@ import { GitLabAIReview } from './index.js';
|
|
|
11
11
|
function parseArgs() {
|
|
12
12
|
const args = process.argv.slice(2);
|
|
13
13
|
const options = {
|
|
14
|
-
enableImpactAnalysis: true, // 默认启用影响分析
|
|
15
|
-
maxAffectedFiles: 10,
|
|
16
14
|
maxFiles: Infinity,
|
|
15
|
+
enableSummary: true,
|
|
16
|
+
// Guard 配置选项
|
|
17
|
+
useGitLabAPI: true, // 使用 GitLab API 获取项目代码
|
|
18
|
+
enableEnhance: true, // 启用智能补充模式
|
|
19
|
+
// 文档加载选项
|
|
20
|
+
loadDocuments: true, // 加载项目文档 (PRD.docx 和 TD.docx)
|
|
21
|
+
documentsPath: 'documents', // 文档路径
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
for (let i = 0; i < args.length; i++) {
|
|
20
25
|
const arg = args[i];
|
|
21
26
|
|
|
22
|
-
if (arg === '--
|
|
23
|
-
options.enableImpactAnalysis = false;
|
|
24
|
-
} else if (arg === '--max-affected-files' && args[i + 1]) {
|
|
25
|
-
options.maxAffectedFiles = parseInt(args[i + 1], 10);
|
|
26
|
-
i++;
|
|
27
|
-
} else if (arg === '--max-files' && args[i + 1]) {
|
|
27
|
+
if (arg === '--max-files' && args[i + 1]) {
|
|
28
28
|
options.maxFiles = parseInt(args[i + 1], 10);
|
|
29
29
|
i++;
|
|
30
|
+
} else if (arg === '--no-summary') {
|
|
31
|
+
options.enableSummary = false;
|
|
32
|
+
} else if (arg === '--no-enhance') {
|
|
33
|
+
// 禁用智能补充模式(直接使用现有 reviewguard.md,不检查是否完整)
|
|
34
|
+
options.enableEnhance = false;
|
|
35
|
+
} else if (arg === '--local') {
|
|
36
|
+
// 使用本地模式(不通过 GitLab API 获取项目代码)
|
|
37
|
+
options.useGitLabAPI = false;
|
|
38
|
+
} else if (arg === '--no-documents') {
|
|
39
|
+
// 禁用文档加载
|
|
40
|
+
options.loadDocuments = false;
|
|
41
|
+
} else if (arg === '--documents-path' && args[i + 1]) {
|
|
42
|
+
// 自定义文档路径
|
|
43
|
+
options.documentsPath = args[i + 1];
|
|
44
|
+
i++;
|
|
30
45
|
} else if (arg === '--help' || arg === '-h') {
|
|
31
46
|
console.log(`
|
|
32
47
|
GitLab AI Review CLI
|
|
@@ -35,29 +50,55 @@ GitLab AI Review CLI
|
|
|
35
50
|
npx gitlab-ai-review [选项]
|
|
36
51
|
|
|
37
52
|
选项:
|
|
38
|
-
--
|
|
39
|
-
--
|
|
40
|
-
--
|
|
41
|
-
--
|
|
53
|
+
--max-files <数量> 最大审查文件数量(默认不限制)
|
|
54
|
+
--no-summary 禁用 MR 总结评论
|
|
55
|
+
--no-enhance 禁用智能补充模式(直接使用现有 reviewguard.md)
|
|
56
|
+
--local 使用本地模式(不通过 GitLab API 获取项目代码)
|
|
57
|
+
--no-documents 禁用项目文档加载(PRD.docx 和 TD.docx)
|
|
58
|
+
--documents-path <路径> 自定义文档文件夹路径(默认 'documents')
|
|
59
|
+
--help, -h 显示帮助信息
|
|
42
60
|
|
|
43
61
|
环境变量:
|
|
44
|
-
GITLAB_TOKEN
|
|
45
|
-
CI_PROJECT_ID
|
|
46
|
-
CI_MERGE_REQUEST_IID
|
|
47
|
-
ARK_API_KEY
|
|
62
|
+
GITLAB_TOKEN GitLab 访问令牌
|
|
63
|
+
CI_PROJECT_ID 项目 ID
|
|
64
|
+
CI_MERGE_REQUEST_IID MR IID
|
|
65
|
+
ARK_API_KEY AI API 密钥
|
|
48
66
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
工作模式说明:
|
|
68
|
+
|
|
69
|
+
📌 默认模式(推荐):
|
|
70
|
+
- 有 reviewguard.md: 结合项目代码检查是否完整,不完整则 AI 补充
|
|
71
|
+
- 无 reviewguard.md: 通过 GitLab API 获取整个项目代码,AI 生成
|
|
72
|
+
- 加载项目文档(PRD.docx 和 TD.docx),提供审查上下文
|
|
73
|
+
|
|
74
|
+
📌 --no-enhance 模式:
|
|
75
|
+
- 有 reviewguard.md: 直接使用,不检查是否完整
|
|
76
|
+
- 无 reviewguard.md: 通过 GitLab API 获取项目代码,AI 生成
|
|
52
77
|
|
|
53
|
-
|
|
54
|
-
|
|
78
|
+
📌 --local 模式:
|
|
79
|
+
- 使用本地文件系统分析项目(适用于本地开发环境)
|
|
55
80
|
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
📌 --no-documents 模式:
|
|
82
|
+
- 不加载项目文档,在没有 PRD/TD 或文档不适用时使用
|
|
83
|
+
|
|
84
|
+
示例:
|
|
85
|
+
# 默认模式(智能补充 + 文档加载)
|
|
86
|
+
npx gitlab-ai-review
|
|
58
87
|
|
|
59
88
|
# 限制审查文件数量
|
|
60
89
|
npx gitlab-ai-review --max-files 3
|
|
90
|
+
|
|
91
|
+
# 禁用智能补充(直接使用现有 reviewguard.md)
|
|
92
|
+
npx gitlab-ai-review --no-enhance
|
|
93
|
+
|
|
94
|
+
# 本地模式
|
|
95
|
+
npx gitlab-ai-review --local
|
|
96
|
+
|
|
97
|
+
# 禁用文档加载
|
|
98
|
+
npx gitlab-ai-review --no-documents
|
|
99
|
+
|
|
100
|
+
# 自定义文档路径
|
|
101
|
+
npx gitlab-ai-review --documents-path docs
|
|
61
102
|
`);
|
|
62
103
|
process.exit(0);
|
|
63
104
|
}
|
|
@@ -71,6 +112,17 @@ async function main() {
|
|
|
71
112
|
|
|
72
113
|
console.log('🚀 GitLab AI Review CLI 启动...\n');
|
|
73
114
|
|
|
115
|
+
// 显示当前模式
|
|
116
|
+
console.log('⚙️ 运行模式:');
|
|
117
|
+
console.log(` - GitLab API 模式: ${cliOptions.useGitLabAPI ? '✅ 开启' : '❌ 关闭 (本地模式)'}`);
|
|
118
|
+
console.log(` - 智能补充模式: ${cliOptions.enableEnhance ? '✅ 开启' : '❌ 关闭'}`);
|
|
119
|
+
console.log(` - MR 总结: ${cliOptions.enableSummary ? '✅ 开启' : '❌ 关闭'}`);
|
|
120
|
+
console.log(` - 文档加载: ${cliOptions.loadDocuments ? '✅ 开启' : '❌ 关闭'}`);
|
|
121
|
+
if (cliOptions.loadDocuments) {
|
|
122
|
+
console.log(` - 文档路径: ${cliOptions.documentsPath}`);
|
|
123
|
+
}
|
|
124
|
+
console.log();
|
|
125
|
+
|
|
74
126
|
try {
|
|
75
127
|
// 1. 创建 SDK 实例(自动从环境变量读取配置)
|
|
76
128
|
const sdk = new GitLabAIReview();
|
|
@@ -81,24 +133,59 @@ async function main() {
|
|
|
81
133
|
console.log(` - Project ID: ${sdk.config.project.projectId}`);
|
|
82
134
|
console.log(` - MR IID: ${sdk.config.project.mergeRequestIid}`);
|
|
83
135
|
console.log(` - AI API Key: ${sdk.config.ai?.arkApiKey ? '✅ 已配置' : '❌ 未配置'}`);
|
|
84
|
-
console.log(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
136
|
+
console.log();
|
|
137
|
+
|
|
138
|
+
// 3. 🎯 初始化 Guard 配置(根据命令行参数选择模式)
|
|
139
|
+
console.log('📚 初始化 Guard 配置...');
|
|
140
|
+
await sdk.initGuardConfig({
|
|
141
|
+
useGitLabAPI: cliOptions.useGitLabAPI,
|
|
142
|
+
enableEnhance: cliOptions.enableEnhance,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const guardStatus = sdk.config.ai?.guardConfig;
|
|
146
|
+
if (guardStatus) {
|
|
147
|
+
console.log(` - Guard 状态: ✅ ${guardStatus.filename}`);
|
|
148
|
+
if (guardStatus.enhanced) {
|
|
149
|
+
console.log(` - 增强状态: ✅ AI 已补充完善`);
|
|
150
|
+
} else if (guardStatus.isComplete) {
|
|
151
|
+
console.log(` - 检查状态: ✅ 内容完整`);
|
|
152
|
+
} else if (guardStatus.generated) {
|
|
153
|
+
console.log(` - 生成状态: ✅ AI 自动生成`);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
console.log(` - Guard 状态: ⚠️ 未找到,使用默认规则`);
|
|
88
157
|
}
|
|
89
158
|
console.log();
|
|
90
159
|
|
|
91
|
-
// 3.
|
|
160
|
+
// 3.5 📚 加载项目文档(PRD.docx 和 TD.docx)
|
|
161
|
+
if (cliOptions.loadDocuments && sdk.config.ai?.arkApiKey) {
|
|
162
|
+
try {
|
|
163
|
+
await sdk.loadProjectDocuments({
|
|
164
|
+
documentsPath: cliOptions.documentsPath,
|
|
165
|
+
enableSummary: true, // 使用 AI 生成文档总结
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.warn(`⚠️ 加载项目文档失败: ${error.message}`);
|
|
169
|
+
console.log(' 将继续进行代码审查(无文档上下文)\n');
|
|
170
|
+
}
|
|
171
|
+
} else if (!cliOptions.loadDocuments) {
|
|
172
|
+
console.log('⏭️ 已禁用文档加载,跳过\n');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 4. 获取 MR 变更信息
|
|
92
176
|
console.log('📥 获取 MR 变更信息...');
|
|
93
177
|
const changes = await sdk.getMergeRequestChanges();
|
|
94
178
|
console.log(`✅ 共发现 ${changes.length} 个文件变更\n`);
|
|
95
179
|
|
|
96
|
-
//
|
|
180
|
+
// 5. 执行 AI 代码审查
|
|
97
181
|
if (sdk.config.ai?.arkApiKey && changes.length > 0) {
|
|
98
182
|
console.log('🤖 开始 AI 代码审查...\n');
|
|
99
183
|
|
|
100
|
-
//
|
|
101
|
-
const results = await sdk.
|
|
184
|
+
// 使用代码审查方法
|
|
185
|
+
const results = await sdk.reviewAndCommentOnLines({
|
|
186
|
+
maxFiles: cliOptions.maxFiles,
|
|
187
|
+
enableSummary: cliOptions.enableSummary,
|
|
188
|
+
});
|
|
102
189
|
|
|
103
190
|
console.log('\n📊 审查结果汇总:');
|
|
104
191
|
const successCount = results.filter(r => r.status === 'success').length;
|
|
@@ -129,4 +216,3 @@ async function main() {
|
|
|
129
216
|
|
|
130
217
|
// 执行主函数
|
|
131
218
|
main();
|
|
132
|
-
|