gitlab-ai-review 4.1.2 → 4.1.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.
Files changed (2) hide show
  1. package/index.js +13 -107
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -16,7 +16,7 @@ import * as ImpactAnalyzer from './lib/impact-analyzer.js';
16
16
  export class GitLabAIReview {
17
17
  constructor(options = {}) {
18
18
  this.name = 'GitLab AI Review SDK';
19
- this.version = '4.1.2';
19
+ this.version = '4.1.4';
20
20
 
21
21
  // 如果传入了配置,使用手动配置;否则使用自动检测
22
22
  if (options.token || options.gitlab) {
@@ -236,33 +236,18 @@ export class GitLabAIReview {
236
236
  for (const review of mergedReviews) {
237
237
  if (review.hasIssue) {
238
238
  try {
239
- // 找到这个评论对应的变更和它所在的 hunk
240
- let targetChange = null;
241
- if (review.oldLine && review.newLine) {
242
- // 修改块:找删除或新增的任意一个
243
- targetChange = meaningfulChanges.find(c =>
244
- (c.lineNumber === review.oldLine && c.type === 'deletion') ||
245
- (c.lineNumber === review.newLine && c.type === 'addition')
246
- );
247
- } else if (review.lineNumber) {
248
- targetChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
249
- }
250
-
251
- // 构建评论位置参数 - 使用 hunk 的起始位置覆盖整个变更块
239
+ // 构建评论位置参数 - 使用实际的变更行号
252
240
  const positionParams = {
253
241
  filePath: fileName,
254
242
  oldPath: change.old_path,
255
243
  };
256
244
 
257
- if (targetChange && targetChange.hunkRange) {
258
- // 使用 hunk 的起始行号,让评论覆盖整个 hunk 范围
259
- positionParams.oldLine = targetChange.hunkRange.oldStart;
260
- positionParams.newLine = targetChange.hunkRange.newStart;
261
- } else if (review.oldLine && review.newLine) {
262
- // 如果找不到 hunk 信息,回退到原来的逻辑
245
+ // 如果是修改块(同时有 oldLine newLine),同时指定两个行号
246
+ if (review.oldLine && review.newLine) {
263
247
  positionParams.oldLine = review.oldLine;
264
248
  positionParams.newLine = review.newLine;
265
249
  } else if (review.lineNumber) {
250
+ // 单独的删除或新增
266
251
  const relatedChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
267
252
  const isDeletion = relatedChange && relatedChange.type === 'deletion';
268
253
  if (isDeletion) {
@@ -272,40 +257,8 @@ export class GitLabAIReview {
272
257
  }
273
258
  }
274
259
 
275
- // 构建评论内容,包含完整的修改块上下文
276
- let commentBody = '🤖 **AI 代码审查**\n\n';
277
-
278
- // 如果是修改块(同时有 oldLine 和 newLine),显示完整的删除和新增
279
- if (review.oldLine && review.newLine) {
280
- // 添加修改块的上下文
281
- const oldChange = meaningfulChanges.find(c => c.lineNumber === review.oldLine && c.type === 'deletion');
282
- const newChange = meaningfulChanges.find(c => c.lineNumber === review.newLine && c.type === 'addition');
283
-
284
- if (oldChange || newChange) {
285
- commentBody += '**📝 修改内容:**\n```diff\n';
286
- if (oldChange) {
287
- commentBody += `- ${oldChange.content}\n`;
288
- }
289
- if (newChange) {
290
- commentBody += `+ ${newChange.content}\n`;
291
- }
292
- commentBody += '```\n\n';
293
- }
294
- } else if (review.lineNumber) {
295
- // 单独的删除或新增
296
- const relatedChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
297
- const isDeletion = relatedChange && relatedChange.type === 'deletion';
298
-
299
- // 添加单个变更的上下文
300
- if (relatedChange) {
301
- commentBody += `**📝 ${isDeletion ? '删除' : '新增'}内容:**\n\`\`\`${isDeletion ? 'diff' : 'javascript'}\n`;
302
- commentBody += `${isDeletion ? '-' : '+'} ${relatedChange.content}\n`;
303
- commentBody += '```\n\n';
304
- }
305
- }
306
-
307
- // 添加 AI 审查意见
308
- commentBody += review.comment;
260
+ // 直接使用 AI 审查意见作为评论内容
261
+ const commentBody = `🤖 **AI 代码审查**\n\n${review.comment}`;
309
262
 
310
263
  const commentResult = await this.gitlabClient.createLineComment(
311
264
  this.config.project.projectId,
@@ -570,33 +523,18 @@ export class GitLabAIReview {
570
523
  for (const review of mergedReviews) {
571
524
  if (review.hasIssue) {
572
525
  try {
573
- // 找到这个评论对应的变更和它所在的 hunk
574
- let targetChange = null;
575
- if (review.oldLine && review.newLine) {
576
- // 修改块:找删除或新增的任意一个
577
- targetChange = meaningfulChanges.find(c =>
578
- (c.lineNumber === review.oldLine && c.type === 'deletion') ||
579
- (c.lineNumber === review.newLine && c.type === 'addition')
580
- );
581
- } else if (review.lineNumber) {
582
- targetChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
583
- }
584
-
585
- // 构建评论位置参数 - 使用 hunk 的起始位置覆盖整个变更块
526
+ // 构建评论位置参数 - 使用实际的变更行号
586
527
  const positionParams = {
587
528
  filePath: fileName,
588
529
  oldPath: change.old_path,
589
530
  };
590
531
 
591
- if (targetChange && targetChange.hunkRange) {
592
- // 使用 hunk 的起始行号,让评论覆盖整个 hunk 范围
593
- positionParams.oldLine = targetChange.hunkRange.oldStart;
594
- positionParams.newLine = targetChange.hunkRange.newStart;
595
- } else if (review.oldLine && review.newLine) {
596
- // 如果找不到 hunk 信息,回退到原来的逻辑
532
+ // 如果是修改块(同时有 oldLine newLine),同时指定两个行号
533
+ if (review.oldLine && review.newLine) {
597
534
  positionParams.oldLine = review.oldLine;
598
535
  positionParams.newLine = review.newLine;
599
536
  } else if (review.lineNumber) {
537
+ // 单独的删除或新增
600
538
  const relatedChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
601
539
  const isDeletion = relatedChange && relatedChange.type === 'deletion';
602
540
  if (isDeletion) {
@@ -606,40 +544,8 @@ export class GitLabAIReview {
606
544
  }
607
545
  }
608
546
 
609
- // 构建评论内容,包含完整的修改块上下文
610
- let commentBody = '🤖 **AI 代码审查**\n\n';
611
-
612
- // 如果是修改块(同时有 oldLine 和 newLine),显示完整的删除和新增
613
- if (review.oldLine && review.newLine) {
614
- // 添加修改块的上下文
615
- const oldChange = meaningfulChanges.find(c => c.lineNumber === review.oldLine && c.type === 'deletion');
616
- const newChange = meaningfulChanges.find(c => c.lineNumber === review.newLine && c.type === 'addition');
617
-
618
- if (oldChange || newChange) {
619
- commentBody += '**📝 修改内容:**\n```diff\n';
620
- if (oldChange) {
621
- commentBody += `- ${oldChange.content}\n`;
622
- }
623
- if (newChange) {
624
- commentBody += `+ ${newChange.content}\n`;
625
- }
626
- commentBody += '```\n\n';
627
- }
628
- } else if (review.lineNumber) {
629
- // 单独的删除或新增
630
- const relatedChange = meaningfulChanges.find(c => c.lineNumber === review.lineNumber);
631
- const isDeletion = relatedChange && relatedChange.type === 'deletion';
632
-
633
- // 添加单个变更的上下文
634
- if (relatedChange) {
635
- commentBody += `**📝 ${isDeletion ? '删除' : '新增'}内容:**\n\`\`\`${isDeletion ? 'diff' : 'javascript'}\n`;
636
- commentBody += `${isDeletion ? '-' : '+'} ${relatedChange.content}\n`;
637
- commentBody += '```\n\n';
638
- }
639
- }
640
-
641
- // 添加 AI 审查意见
642
- commentBody += review.comment;
547
+ // 直接使用 AI 审查意见作为评论内容
548
+ const commentBody = `🤖 **AI 代码审查**\n\n${review.comment}`;
643
549
 
644
550
  const commentResult = await this.gitlabClient.createLineComment(
645
551
  this.config.project.projectId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitlab-ai-review",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
4
4
  "description": "GitLab AI Review SDK with Impact Analysis - 支持影响分析、删除符号检测、注释代码识别、文件内部冲突检查、智能文件过滤的智能代码审查工具",
5
5
  "main": "index.js",
6
6
  "type": "module",