gitlab-ai-review 2.1.0 → 2.2.0
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/index.js +6 -5
- package/lib/prompt-tools.js +6 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as DiffParser from './lib/diff-parser.js';
|
|
|
15
15
|
export class GitLabAIReview {
|
|
16
16
|
constructor(options = {}) {
|
|
17
17
|
this.name = 'GitLab AI Review SDK';
|
|
18
|
-
this.version = '2.
|
|
18
|
+
this.version = '2.2.0';
|
|
19
19
|
|
|
20
20
|
// 如果传入了配置,使用手动配置;否则使用自动检测
|
|
21
21
|
if (options.token || options.gitlab) {
|
|
@@ -181,17 +181,18 @@ export class GitLabAIReview {
|
|
|
181
181
|
/**
|
|
182
182
|
* AI 审查 MR 的所有有意义的变更并自动添加行级评论(按文件批量处理)
|
|
183
183
|
* @param {Object} options - 选项
|
|
184
|
-
* @param {number} options.maxFiles -
|
|
184
|
+
* @param {number} options.maxFiles - 最大审查文件数量(默认不限制)
|
|
185
185
|
* @returns {Promise<Array>} 评论结果数组
|
|
186
186
|
*/
|
|
187
187
|
async reviewAndCommentOnLines(options = {}) {
|
|
188
|
-
const { maxFiles =
|
|
188
|
+
const { maxFiles = Infinity } = options;
|
|
189
189
|
const changes = await this.getMergeRequestChanges();
|
|
190
190
|
const results = [];
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
const filesToReview = maxFiles === Infinity ? changes.length : Math.min(maxFiles, changes.length);
|
|
193
|
+
console.log(`共 ${changes.length} 个文件需要审查${maxFiles === Infinity ? '(不限制数量)' : `(最多审查 ${maxFiles} 个)`}`);
|
|
193
194
|
|
|
194
|
-
for (const change of changes.slice(0,
|
|
195
|
+
for (const change of changes.slice(0, filesToReview)) {
|
|
195
196
|
const fileName = change.new_path || change.old_path;
|
|
196
197
|
|
|
197
198
|
try {
|
package/lib/prompt-tools.js
CHANGED
|
@@ -136,7 +136,8 @@ export function buildFileReviewPrompt(fileName, meaningfulChanges) {
|
|
|
136
136
|
|
|
137
137
|
1. 仔细审查每一行变更,判断是否存在问题
|
|
138
138
|
2. **只对有问题的行提出审查意见**,没有问题的行不需要评论
|
|
139
|
-
3.
|
|
139
|
+
3. **必须使用中文**返回审查意见
|
|
140
|
+
4. 返回 JSON 格式的结果,格式如下:
|
|
140
141
|
|
|
141
142
|
\`\`\`json
|
|
142
143
|
{
|
|
@@ -144,7 +145,7 @@ export function buildFileReviewPrompt(fileName, meaningfulChanges) {
|
|
|
144
145
|
{
|
|
145
146
|
"lineNumber": 15,
|
|
146
147
|
"hasIssue": true,
|
|
147
|
-
"comment": "
|
|
148
|
+
"comment": "这里用中文描述具体的问题和改进建议"
|
|
148
149
|
},
|
|
149
150
|
{
|
|
150
151
|
"lineNumber": 20,
|
|
@@ -154,8 +155,9 @@ export function buildFileReviewPrompt(fileName, meaningfulChanges) {
|
|
|
154
155
|
}
|
|
155
156
|
\`\`\`
|
|
156
157
|
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
5. 如果所有代码都没有问题,返回空的 reviews 数组:\`{"reviews": []}\`
|
|
159
|
+
6. 只返回 JSON,不要包含其他文字说明
|
|
160
|
+
7. comment 字段必须使用中文,要简洁明了`;
|
|
159
161
|
|
|
160
162
|
return prompt;
|
|
161
163
|
}
|