job51-gitlab-cr-node-jt-1 2.4.2 → 2.4.4
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/.claude/skills/simple-code-review/SKILL.md +12 -4
- package/index.js +55 -23
- package/log.txt +0 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
---
|
|
1
|
+
---
|
|
2
2
|
name: simple-code-review
|
|
3
3
|
description: 代码审查技能,审查变更代码并输出 REPORT 和 LINE_INFO
|
|
4
4
|
---
|
|
@@ -37,9 +37,16 @@ description: 代码审查技能,审查变更代码并输出 REPORT 和 LINE_IN
|
|
|
37
37
|
|
|
38
38
|
### 🔴 严重问题
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
---
|
|
41
|
+
[问题描述]<br/>
|
|
42
|
+
**文件及行号**:[文件路径:行号]<br/>
|
|
43
|
+
**修改建议**:[正确示例代码]
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
[问题描述]<br/>
|
|
47
|
+
**文件及行号**:[文件路径:行号]<br/>
|
|
42
48
|
**修改建议**:[正确示例代码]
|
|
49
|
+
---
|
|
43
50
|
|
|
44
51
|
</REPORT>
|
|
45
52
|
|
|
@@ -49,4 +56,5 @@ description: 代码审查技能,审查变更代码并输出 REPORT 和 LINE_IN
|
|
|
49
56
|
|
|
50
57
|
**说明**:
|
|
51
58
|
- 无问题时省略对应标题,但 `<LINE_INFO>` 必须输出(空数组:`[]`)
|
|
52
|
-
-
|
|
59
|
+
- 每个问题用 `---` 分割线分隔,方便切分
|
|
60
|
+
- 行号格式参考 @.claude/rules/code-review-rules.md 第 19 条
|
package/index.js
CHANGED
|
@@ -512,30 +512,32 @@ ${diffObject.diff}`;
|
|
|
512
512
|
*/
|
|
513
513
|
extractSingleProblemReport(fullReport, problemIndex) {
|
|
514
514
|
const lines = fullReport.split('\n');
|
|
515
|
-
//
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
let
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (nextProblemRegex.test(lines[j])) {
|
|
528
|
-
endIndex = j;
|
|
529
|
-
break;
|
|
515
|
+
// 使用 --- 分割线来切分问题
|
|
516
|
+
const problemBlocks = [];
|
|
517
|
+
let currentBlock = [];
|
|
518
|
+
let inBlock = false;
|
|
519
|
+
|
|
520
|
+
for (const line of lines) {
|
|
521
|
+
if (line.trim() === '---') {
|
|
522
|
+
if (inBlock) {
|
|
523
|
+
// 块结束
|
|
524
|
+
if (currentBlock.length > 0) {
|
|
525
|
+
problemBlocks.push(currentBlock.join('\n'));
|
|
526
|
+
currentBlock = [];
|
|
530
527
|
}
|
|
528
|
+
inBlock = false;
|
|
529
|
+
} else {
|
|
530
|
+
// 块开始
|
|
531
|
+
inBlock = true;
|
|
531
532
|
}
|
|
532
|
-
|
|
533
|
+
} else if (inBlock) {
|
|
534
|
+
currentBlock.push(line);
|
|
533
535
|
}
|
|
534
536
|
}
|
|
535
537
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return
|
|
538
|
+
// 返回第 problemIndex 个问题(索引从 1 开始)
|
|
539
|
+
if (problemIndex >= 1 && problemIndex <= problemBlocks.length) {
|
|
540
|
+
return problemBlocks[problemIndex - 1];
|
|
539
541
|
}
|
|
540
542
|
|
|
541
543
|
// 如果无法提取,返回完整报告(降级处理)
|
|
@@ -583,6 +585,13 @@ ${diffObject.diff}`;
|
|
|
583
585
|
const headSha = versionInfo.head_commit_sha;
|
|
584
586
|
const startSha = versionInfo.start_commit_sha;
|
|
585
587
|
debugLog(`获取到版本信息 - base: ${baseSha}, head: ${headSha}, start: ${startSha}`);
|
|
588
|
+
|
|
589
|
+
// 解析 diff 头信息,计算有效行号范围
|
|
590
|
+
const newStart = diff_info.new_start || 1;
|
|
591
|
+
const newCount = diff_info.new_count || 1;
|
|
592
|
+
const maxValidLine = newStart + newCount - 1;
|
|
593
|
+
debugLog(`Diff 块行号范围:[${newStart}, ${maxValidLine}],共 ${newCount} 行`);
|
|
594
|
+
|
|
586
595
|
const allLineInfo = this.parseAllLineInfoFromReviewResult(lineInfoTag);
|
|
587
596
|
debugLog(`解析到 ${allLineInfo.length} 个问题的行号信息`);
|
|
588
597
|
if (allLineInfo.length === 0) {
|
|
@@ -594,16 +603,39 @@ ${diffObject.diff}`;
|
|
|
594
603
|
const problemInfo = allLineInfo[i];
|
|
595
604
|
debugLog(`处理第 ${i + 1}/${allLineInfo.length} 个问题:文件=${problemInfo.new_path}, 行号=${problemInfo.new_line}`);
|
|
596
605
|
const singleProblemContent = this.extractSingleProblemReport(fullReportContent, i + 1);
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
606
|
+
|
|
607
|
+
// 行号有效性验证和修正
|
|
608
|
+
let targetLine;
|
|
609
|
+
let originalLine = problemInfo.new_line;
|
|
610
|
+
let needsGeneralDiscussion = false;
|
|
611
|
+
|
|
601
612
|
if (problemInfo.old_line && !problemInfo.new_line) {
|
|
613
|
+
// 删除代码,使用 old_line
|
|
602
614
|
targetLine = {
|
|
603
615
|
old_path: problemInfo.old_path,
|
|
604
616
|
old_line: problemInfo.old_line
|
|
605
617
|
};
|
|
618
|
+
} else if (problemInfo.new_line) {
|
|
619
|
+
// 验证新行号是否在有效范围内
|
|
620
|
+
if (problemInfo.new_line < newStart || problemInfo.new_line > maxValidLine) {
|
|
621
|
+
debugLog(`⚠️ 行号 ${problemInfo.new_line} 超出有效范围 [${newStart}, ${maxValidLine}],改用一般讨论`);
|
|
622
|
+
needsGeneralDiscussion = true;
|
|
623
|
+
} else {
|
|
624
|
+
targetLine = {
|
|
625
|
+
new_path: problemInfo.new_path,
|
|
626
|
+
new_line: problemInfo.new_line
|
|
627
|
+
};
|
|
628
|
+
}
|
|
606
629
|
}
|
|
630
|
+
|
|
631
|
+
if (needsGeneralDiscussion) {
|
|
632
|
+
// 行号无效,改用一般讨论
|
|
633
|
+
debugLog(`第 ${i + 1} 个问题的行号 ${originalLine} 无效,发布为一般讨论`);
|
|
634
|
+
await this.createGeneralDiscussion(projectId, mergeRequestIid, file_path_with_line, singleProblemContent);
|
|
635
|
+
debugLog(`第 ${i + 1} 个问题的评论已发布 (作为一般讨论,行号无效)`);
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
|
|
607
639
|
debugLog(`第 ${i + 1} 个问题的 targetLine: ${JSON.stringify(targetLine)}`);
|
|
608
640
|
const payload = {
|
|
609
641
|
body: singleProblemContent,
|
package/log.txt
ADDED
|
File without changes
|