job51-gitlab-cr-node-jt-1 2.9.9 → 3.0.1
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 +69 -35
- 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
|
-
|
|
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
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
}
|
|
@@ -549,40 +569,54 @@ ${allReportsText}
|
|
|
549
569
|
|
|
550
570
|
// 大文件模式下的特殊提示
|
|
551
571
|
const largeFilePrompt = isLargeFile ? `
|
|
552
|
-
**⚠️
|
|
553
|
-
|
|
554
|
-
1.
|
|
555
|
-
2.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
3. 发现问题时,准确报告行号(基于文件内容的实际行号)
|
|
572
|
+
**⚠️ 大文件审查模式 - 强制格式要求**:
|
|
573
|
+
这是完整文件审查(GitLab diff截断),所有代码都是新增内容。
|
|
574
|
+
1. 直接输出审查报告,不要先分析后格式化
|
|
575
|
+
2. 发现问题后立即按模板格式写入 REPORT 和 LINE_INFO
|
|
576
|
+
3. 行号基于完整文件实际行号计算
|
|
577
|
+
4. **严禁在输出中写 "Let me format" 等中间过程文本**
|
|
578
|
+
5. **必须在 </REPORT> 后立即输出 <LINE_INFO> 标签,包含每个问题的行号**
|
|
560
579
|
` : '';
|
|
561
580
|
|
|
562
581
|
const prompt = `请调用 simple-code-review 技能审核代码变更。
|
|
563
582
|
文件路径:${filePath}
|
|
564
583
|
${largeFilePrompt}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
584
|
+
**⚠️ 强制输出格式要求(违反会导致审查结果丢失)**:
|
|
585
|
+
|
|
586
|
+
你必须直接输出以下格式,不要输出任何分析过程、思考过程或中间文本:
|
|
587
|
+
|
|
588
|
+
<REPORT>
|
|
589
|
+
## 🤖 AI 代码审查结果
|
|
590
|
+
|
|
591
|
+
### 🔴 严重问题
|
|
592
|
+
|
|
593
|
+
**问题 1**:[问题描述]<br/>
|
|
594
|
+
**文件及行号**:[文件路径:实际行号]<br/>
|
|
595
|
+
**修改建议**:[修复建议]
|
|
596
|
+
|
|
597
|
+
**问题 2**:[问题描述]<br/>
|
|
598
|
+
**文件及行号**:[文件路径:实际行号]<br/>
|
|
599
|
+
**修改建议**:[修复建议]
|
|
600
|
+
|
|
601
|
+
...(更多问题按同样格式)
|
|
602
|
+
|
|
603
|
+
</REPORT>
|
|
604
|
+
|
|
605
|
+
<LINE_INFO>
|
|
606
|
+
[{"new_path":"文件路径","new_line":实际行号},{"new_path":"文件路径","new_line":实际行号}]
|
|
607
|
+
</LINE_INFO>
|
|
608
|
+
|
|
609
|
+
**审查重点**:
|
|
610
|
+
1. 资源泄漏:JDBC/文件流未关闭 → 报告资源创建行号
|
|
611
|
+
2. 框架问题:@Async返回具体类型 → 报告方法定义行号
|
|
612
|
+
3. 循环逻辑:状态过期、累积不一致 → 报告循环内出错行号
|
|
613
|
+
4. 异常吞没:catch块空实现 → 报告catch行号
|
|
614
|
+
5. 空指针:包装类型拆箱 → 报告使用行号
|
|
615
|
+
|
|
616
|
+
**关键**:
|
|
617
|
+
- 有严重问题时,LINE_INFO 必须包含对应行号,否则结果被丢弃
|
|
618
|
+
- 无问题时输出 <LINE_INFO>[]</LINE_INFO>
|
|
619
|
+
- 不要输出 "Let me analyze"、"Let me format" 等文本`;
|
|
586
620
|
//打印
|
|
587
621
|
debugLog(`[${blockIdentifier}] Claude命令: ${prompt}`);
|
|
588
622
|
// 最多重试5次,直到结果包含"🤖 AI 代码审查结果"或达到最大重试次数
|