gitlab-ai-review 3.6.0 → 3.6.2

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 CHANGED
@@ -209,6 +209,10 @@ export class GitLabAIReview {
209
209
  for (const review of fileReview.reviews) {
210
210
  if (review.hasIssue) {
211
211
  try {
212
+ // 找到对应的变更,判断是删除还是新增
213
+ const relatedChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
214
+ const isDeletion = relatedChange && relatedChange.type === 'deletion';
215
+
212
216
  const commentResult = await this.gitlabClient.createLineComment(
213
217
  this.config.project.projectId,
214
218
  this.config.project.mergeRequestIid,
@@ -216,7 +220,8 @@ export class GitLabAIReview {
216
220
  {
217
221
  filePath: fileName,
218
222
  oldPath: change.old_path,
219
- newLine: review.lineNumber,
223
+ // 删除的行使用 oldLine,新增的行使用 newLine
224
+ ...(isDeletion ? { oldLine: review.lineNumber } : { newLine: review.lineNumber }),
220
225
  }
221
226
  );
222
227
 
@@ -259,6 +259,13 @@ export function buildFileReviewWithImpactPrompt(fileName, meaningfulChanges, imp
259
259
 
260
260
  prompt += `---\n\n`;
261
261
  }
262
+
263
+ prompt += `**🔍 跨文件影响分析提醒:**\n`;
264
+ prompt += `上述"受影响的文件"是通过文本搜索找到的,可能存在以下情况:\n`;
265
+ prompt += `1. **局部定义**:受影响的文件中可能有同名的局部变量、函数参数、类方法等\n`;
266
+ prompt += `2. **重新导入**:受影响的文件可能从其他模块导入了同名符号\n`;
267
+ prompt += `3. **命名空间**:可能在不同的命名空间或作用域中\n`;
268
+ prompt += `\n**请仔细检查代码片段,只有确认是引用被删除的符号时,才报告为影响!**\n\n`;
262
269
  }
263
270
 
264
271
  // 添加代码变更
@@ -305,10 +312,15 @@ export function buildFileReviewWithImpactPrompt(fileName, meaningfulChanges, imp
305
312
 
306
313
  1. 仔细审查每一行变更,判断是否存在问题
307
314
  2. 注意区分**修改**和**重复定义**:如果同一位置有删除(-)和新增(+),这是修改,不是重复
308
- 3. 优先检查"类型: 删除"的代码,确认是否有其他地方仍在使用
309
- 4. **只对有问题的行提出审查意见**,没有问题的行不需要评论
310
- 5. **必须使用中文**返回审查意见
311
- 6. **必须返回标准 JSON 格式**,不要用其他格式,结构如下:
315
+ 3. **🚨 检查删除的符号时,必须考虑作用域:**
316
+ - 检查使用处是否有**局部定义**(函数参数、局部变量、解构等)
317
+ - 检查使用处是否**重新导入**了同名符号
318
+ - 只有确认使用的是**被删除的这个符号**时,才报告为错误
319
+ - 示例:如果删除了全局函数 \`getData()\`,但使用处有 \`const getData = () => {...}\` 或 \`import { getData } from 'other'\`,则**不是问题**
320
+ 4. 优先检查"类型: 删除"的代码,确认是否有其他地方仍在使用
321
+ 5. **只对有问题的行提出审查意见**,没有问题的行不需要评论
322
+ 6. **必须使用中文**返回审查意见
323
+ 7. **必须返回标准 JSON 格式**,不要用其他格式,结构如下:
312
324
 
313
325
  \`\`\`json
314
326
  {
@@ -336,9 +348,6 @@ export function buildFileReviewWithImpactPrompt(fileName, meaningfulChanges, imp
336
348
  - comment 是一个字符串,可以包含换行符 \\n 来格式化内容
337
349
  - 不要自创格式,必须参考上面"项目特定的审查规则"中的示例
338
350
 
339
- **示例:**
340
- 如果 reviewguard.md 中定义了格式,删除第 15 行的函数时,comment 内容必须是:
341
- "【严重程度评分:8/10】\\n\\n📋 问题描述:\\n删除了函数 fetchData 但该函数仍被多处使用\\n\\n🔍 影响分析:\\n• 当前文件:函数定义被完全移除\\n• 受影响的其他文件:components/UserList.vue (第 45 行)\\n\\n💡 改进建议:\\n1. 恢复此函数或提供替代方案\\n2. 先标记为 @deprecated"
342
351
 
343
352
  7. 如果所有代码都没有问题,返回空的 reviews 数组:\`{"reviews": []}\`
344
353
  8. **只返回 JSON**,不要在 JSON 外面添加任何文字说明`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitlab-ai-review",
3
- "version": "3.6.0",
3
+ "version": "3.6.2",
4
4
  "description": "GitLab AI Review SDK with Impact Analysis - 支持影响分析、删除符号检测、注释代码识别、文件内部冲突检查、智能文件过滤的智能代码审查工具",
5
5
  "main": "index.js",
6
6
  "type": "module",