job51-gitlab-cr-node-jt-1 3.0.0 → 3.0.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.
Files changed (2) hide show
  1. package/index.js +27 -35
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -144,7 +144,22 @@ class GitLabCodeReviewer {
144
144
  const blockStartTime = Date.now();
145
145
  const blockIdentifier = `${diffObject.new_path || diffObject.old_path}#large-file`;
146
146
  const review_result = await this.reviewDiffWithClaudeUsingFile(tmpFileName, blockIdentifier, true);
147
- const blockObj = { ...diffObject, review_result, temp_file_path: tmpFileName, is_large_file: true };
147
+
148
+ // 对于大文件,设置完整的行号范围信息(使用文件总行数)
149
+ const fileLineCount = fileContent.split('\n').length;
150
+ const blockObj = {
151
+ ...diffObject,
152
+ review_result,
153
+ temp_file_path: tmpFileName,
154
+ is_large_file: true,
155
+ // 设置行号范围信息,让行级评论验证能够通过
156
+ line_info: {
157
+ old_start: diffObject.new_file ? 0 : 1,
158
+ old_count: diffObject.new_file ? 0 : fileLineCount,
159
+ new_start: 1,
160
+ new_count: fileLineCount
161
+ }
162
+ };
148
163
 
149
164
  // 记录审查指标
150
165
  const reviewTime = Date.now() - blockStartTime;
@@ -156,11 +171,16 @@ class GitLabCodeReviewer {
156
171
 
157
172
  // 检查审查结果中是否包含严重问题
158
173
  if (blockObj.review_result && blockObj.review_result.reportContent && blockObj.review_result.reportContent.includes('严重问题')) {
159
- // 对于大文件,发布为一般讨论(无法精确定位行号)
160
- const file_path_with_line = `${diffObject.new_path || diffObject.old_path}#L1`;
161
- await this.createGeneralDiscussion(projectId, mergeRequestIid, file_path_with_line, blockObj.review_result.reportContent);
162
- debugLog(`大文件审查结果已发布为一般讨论: ${file_path_with_line}`);
163
- this.metrics.recordCommentPublished();
174
+ // 尝试发布行级评论(大文件现在也有 line_info,可以验证行号)
175
+ const commentResult = await this.postSingleCommentToGitLab(projectId, mergeRequestIid, {
176
+ diff_info: blockObj,
177
+ block_index: blockIndex,
178
+ review_result: blockObj.review_result,
179
+ });
180
+ if (commentResult && commentResult.hallucination_detected) {
181
+ hallucinationDetected = true;
182
+ }
183
+ debugLog(`大文件审查结果已尝试发布行级评论: ${diffObject.new_path || diffObject.old_path}`);
164
184
  } else {
165
185
  debugLog(`大文件审查未发现严重问题: ${diffObject.new_path || diffObject.old_path}`);
166
186
  }
@@ -563,35 +583,7 @@ ${allReportsText}
563
583
  ${largeFilePrompt}
564
584
  **⚠️ 强制输出格式要求(违反会导致审查结果丢失)**:
565
585
 
566
- 你必须直接输出以下格式,不要输出任何分析过程、思考过程或中间文本:
567
-
568
- <REPORT>
569
- ## 🤖 AI 代码审查结果
570
-
571
- ### 🔴 严重问题
572
-
573
- **问题 1**:[问题描述]<br/>
574
- **文件及行号**:[文件路径:实际行号]<br/>
575
- **修改建议**:[修复建议]
576
-
577
- **问题 2**:[问题描述]<br/>
578
- **文件及行号**:[文件路径:实际行号]<br/>
579
- **修改建议**:[修复建议]
580
-
581
- ...(更多问题按同样格式)
582
-
583
- </REPORT>
584
-
585
- <LINE_INFO>
586
- [{"new_path":"文件路径","new_line":实际行号},{"new_path":"文件路径","new_line":实际行号}]
587
- </LINE_INFO>
588
-
589
- **审查重点**:
590
- 1. 资源泄漏:JDBC/文件流未关闭 → 报告资源创建行号
591
- 2. 框架问题:@Async返回具体类型 → 报告方法定义行号
592
- 3. 循环逻辑:状态过期、累积不一致 → 报告循环内出错行号
593
- 4. 异常吞没:catch块空实现 → 报告catch行号
594
- 5. 空指针:包装类型拆箱 → 报告使用行号
586
+ 必须以规定格式输出,不要输出任何分析过程、思考过程或中间文本:
595
587
 
596
588
  **关键**:
597
589
  - 有严重问题时,LINE_INFO 必须包含对应行号,否则结果被丢弃
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "job51-gitlab-cr-node-jt-1",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "GitLab merge request code review tool with AI-powered analysis and project context support",
5
5
  "main": "index.js",
6
6
  "bin": {