gitlab-ai-review 3.0.0 → 3.1.0

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 (3) hide show
  1. package/README.md +4 -0
  2. package/index.js +38 -4
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -16,6 +16,10 @@ GitLab AI Review SDK - 支持 CI/CD 自动配置和手动配置
16
16
  - 完整上下文分析
17
17
  - ✅ 行级 AI 代码审查
18
18
  - ✅ 批量审查和评论
19
+ - ✅ **智能文件过滤** 🆕
20
+ - 自动跳过 Markdown 文件 (`.md`)
21
+ - 自动跳过配置文件 (`.json`, `.yml`, `.yaml`)
22
+ - 自动跳过依赖锁文件 (`package-lock.json`, `yarn.lock` 等)
19
23
 
20
24
  ## 安装
21
25
 
package/index.js CHANGED
@@ -138,6 +138,38 @@ export class GitLabAIReview {
138
138
  return this.aiClient;
139
139
  }
140
140
 
141
+ /**
142
+ * 过滤不需要审查的文件
143
+ * @param {Array} changes - 变更列表
144
+ * @returns {Array} 过滤后的变更列表
145
+ */
146
+ filterReviewableFiles(changes) {
147
+ const excludePatterns = [
148
+ /\.md$/i, // Markdown 文件
149
+ /\.txt$/i, // 文本文件
150
+ /\.json$/i, // JSON 配置文件
151
+ /\.yml$/i, // YAML 配置文件
152
+ /\.yaml$/i, // YAML 配置文件
153
+ /package-lock\.json$/i, // 依赖锁文件
154
+ /yarn\.lock$/i, // Yarn 锁文件
155
+ /pnpm-lock\.yaml$/i // PNPM 锁文件
156
+ ];
157
+
158
+ const filtered = changes.filter(change => {
159
+ const fileName = change.new_path || change.old_path;
160
+ const shouldExclude = excludePatterns.some(pattern => pattern.test(fileName));
161
+
162
+ if (shouldExclude) {
163
+ console.log(`⏭️ 跳过文件: ${fileName} (不需要代码审查)`);
164
+ return false;
165
+ }
166
+
167
+ return true;
168
+ });
169
+
170
+ return filtered;
171
+ }
172
+
141
173
  /**
142
174
  * AI 审查 MR 的所有有意义的变更并自动添加行级评论(按文件批量处理)
143
175
  * @param {Object} options - 选项
@@ -146,11 +178,12 @@ export class GitLabAIReview {
146
178
  */
147
179
  async reviewAndCommentOnLines(options = {}) {
148
180
  const { maxFiles = Infinity } = options;
149
- const changes = await this.getMergeRequestChanges();
181
+ const allChanges = await this.getMergeRequestChanges();
182
+ const changes = this.filterReviewableFiles(allChanges);
150
183
  const results = [];
151
184
 
152
185
  const filesToReview = maxFiles === Infinity ? changes.length : Math.min(maxFiles, changes.length);
153
- console.log(`共 ${changes.length} 个文件需要审查${maxFiles === Infinity ? '(不限制数量)' : `(最多审查 ${maxFiles} 个)`}`);
186
+ console.log(`共 ${changes.length} 个文件需要审查${maxFiles === Infinity ? '(不限制数量)' : `(最多审查 ${maxFiles} 个)`}(已过滤 ${allChanges.length - changes.length} 个文件)`);
154
187
 
155
188
  for (const change of changes.slice(0, filesToReview)) {
156
189
  const fileName = change.new_path || change.old_path;
@@ -280,13 +313,14 @@ export class GitLabAIReview {
280
313
  enableImpactAnalysis = true
281
314
  } = options;
282
315
 
283
- const changes = await this.getMergeRequestChanges();
316
+ const allChanges = await this.getMergeRequestChanges();
317
+ const changes = this.filterReviewableFiles(allChanges);
284
318
  const mrInfo = await this.getMergeRequest();
285
319
  const ref = mrInfo.target_branch || 'main';
286
320
  const results = [];
287
321
 
288
322
  const filesToReview = maxFiles === Infinity ? changes.length : Math.min(maxFiles, changes.length);
289
- console.log(`共 ${changes.length} 个文件需要审查${maxFiles === Infinity ? '(不限制数量)' : `(最多审查 ${maxFiles} 个)`}`);
323
+ console.log(`共 ${changes.length} 个文件需要审查${maxFiles === Infinity ? '(不限制数量)' : `(最多审查 ${maxFiles} 个)`}(已过滤 ${allChanges.length - changes.length} 个文件)`);
290
324
  console.log(`影响分析: ${enableImpactAnalysis ? '已启用' : '已禁用'}`);
291
325
 
292
326
  for (const change of changes.slice(0, filesToReview)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gitlab-ai-review",
3
- "version": "3.0.0",
4
- "description": "GitLab AI Review SDK with Impact Analysis - 支持影响分析、删除符号检测、文件内部冲突检查的智能代码审查工具",
3
+ "version": "3.1.0",
4
+ "description": "GitLab AI Review SDK with Impact Analysis - 支持影响分析、删除符号检测、文件内部冲突检查、智能文件过滤的智能代码审查工具",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "bin": {