job51-gitlab-cr-node-jt-1 3.1.0 → 3.1.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 (3) hide show
  1. package/README.md +2 -1
  2. package/index.js +147 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -47,7 +47,8 @@ gitlab-cr
47
47
  - 生成结构化的审查报告
48
48
  - 将审查结果发布到 GitLab MR
49
49
  - 自动跳过测试文件(如 `*Test.java`、`*.test.js` 等)
50
- - 自动跳过 DTO/VO 文件(如 `*Dto.java`、`*VO.java`、`*Request.java` 等)
50
+ - 自动跳过 DTO/VO/Query 文件(如 `*Dto.java`、`*VO.java`、`*Query.java`、`*Request.java` 等)
51
+ - 自动跳过非代码文件(如配置文件、文档文件、资源文件等)
51
52
 
52
53
  ## 依赖要求
53
54
 
package/index.js CHANGED
@@ -98,12 +98,14 @@ class GitLabCodeReviewer {
98
98
  // 提取文件名(不含扩展名)
99
99
  const fileName = normalizedPath.split('/').pop() || '';
100
100
 
101
- // DTO/VO 目录模式(整个目录都是数据模型)
101
+ // DTO/VO/Query 目录模式(整个目录都是数据模型)
102
102
  const dtoVoDirPatterns = [
103
103
  '/dto/', // Java: com/example/dto/
104
104
  '/DTO/', // 大写形式
105
105
  '/vo/', // Java: com/example/vo/
106
106
  '/VO/', // 大写形式
107
+ '/query/', // Query 对象目录
108
+ '/Query/', // 大写形式
107
109
  '/model/', // 通用模型目录
108
110
  '/models/', // 通用模型目录
109
111
  '/entity/', // 实体类目录(有时也是纯数据)
@@ -119,13 +121,14 @@ class GitLabCodeReviewer {
119
121
  }
120
122
  }
121
123
 
122
- // DTO/VO 文件命名模式
124
+ // DTO/VO/Query 文件命名模式
123
125
  // 匹配文件名中包含或以这些后缀结尾的情况
124
126
  const dtoVoPatterns = [
125
127
  'Dto', // Java: XxxDto.java
126
128
  'DTO', // Java: XxxDTO.java
127
129
  'Vo', // Java: XxxVo.java
128
130
  'VO', // Java: XxxVO.java
131
+ 'Query', // Query 对象(纯数据查询条件)
129
132
  'Request', // Request 对象通常也是纯数据
130
133
  'Response', // Response 对象通常也是纯数据
131
134
  'Form', // Form 对象
@@ -143,12 +146,13 @@ class GitLabCodeReviewer {
143
146
  }
144
147
  }
145
148
 
146
- // Java 特殊处理:文件名以常见 DTO/VO 后缀结尾
149
+ // Java 特殊处理:文件名以常见 DTO/VO/Query 后缀结尾
147
150
  const dtoVoEndPatterns = [
148
151
  'Dto.java',
149
152
  'DTO.java',
150
153
  'Vo.java',
151
154
  'VO.java',
155
+ 'Query.java',
152
156
  'Request.java',
153
157
  'Response.java',
154
158
  'Form.java',
@@ -159,6 +163,7 @@ class GitLabCodeReviewer {
159
163
  'DTO.kt',
160
164
  'Vo.kt',
161
165
  'VO.kt',
166
+ 'Query.kt',
162
167
  'Request.kt',
163
168
  'Response.kt',
164
169
  // TypeScript/JavaScript
@@ -170,6 +175,8 @@ class GitLabCodeReviewer {
170
175
  'Vo.js',
171
176
  'VO.ts',
172
177
  'VO.js',
178
+ 'Query.ts',
179
+ 'Query.js',
173
180
  ];
174
181
 
175
182
  for (const pattern of dtoVoEndPatterns) {
@@ -181,6 +188,130 @@ class GitLabCodeReviewer {
181
188
  return false;
182
189
  }
183
190
 
191
+ /**
192
+ * 判断文件是否是非代码文件(需要跳过审查)
193
+ * 非代码文件包括:配置文件、文档文件、资源文件、数据文件等
194
+ * @param {string} filePath 文件路径
195
+ * @returns {boolean} 是否是非代码文件
196
+ */
197
+ isNonCodeFile(filePath) {
198
+ if (!filePath) return false;
199
+
200
+ // 标准化路径(统一使用 / 分隔符)
201
+ const normalizedPath = filePath.replace(/\\/g, '/');
202
+
203
+ // 提取文件名和扩展名
204
+ const fileName = normalizedPath.split('/').pop() || '';
205
+ const ext = fileName.split('.').pop()?.toLowerCase() || '';
206
+
207
+ // 非代码文件扩展名列表
208
+ const nonCodeExtensions = [
209
+ // 配置文件
210
+ 'json', // JSON 配置文件(如 package.json, tsconfig.json 等)
211
+ 'yaml', 'yml', // YAML 配置文件
212
+ 'xml', // XML 配置文件(如 pom.xml, logback.xml 等)
213
+ 'properties', // Java Properties 文件
214
+ 'toml', // TOML 配置文件
215
+ 'ini', // INI 配置文件
216
+ 'conf', 'config', // 通用配置文件
217
+ 'env', // 环境变量文件
218
+ 'editorconfig', // EditorConfig 文件
219
+ 'gitignore', // Git ignore 文件
220
+ 'gitattributes', // Git attributes 文件
221
+ 'dockerignore', // Docker ignore 文件
222
+
223
+ // 文档文件
224
+ 'md', 'markdown', // Markdown 文档
225
+ 'txt', // 文本文件
226
+ 'rst', // reStructuredText 文档
227
+ 'adoc', 'asciidoc', // AsciiDoc 文档
228
+ 'doc', 'docx', // Word 文档
229
+ 'pdf', // PDF 文档
230
+ 'changelog', // 变更日志
231
+ 'license', // 许可证文件
232
+ 'readme', // README 文件(无扩展名情况)
233
+
234
+ // 资源文件
235
+ 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'ico', 'svg', 'webp', // 图片
236
+ 'woff', 'woff2', 'ttf', 'otf', 'eot', // 字体文件
237
+ 'mp3', 'mp4', 'wav', 'avi', 'mov', 'wmv', 'flv', // 音视频文件
238
+ 'zip', 'tar', 'gz', 'rar', '7z', 'jar', 'war', // 压缩包
239
+
240
+ // 数据文件
241
+ 'csv', // CSV 数据文件
242
+ 'xls', 'xlsx', // Excel 文件
243
+ 'sql', // SQL 脚本文件(纯数据导出)
244
+ 'db', 'sqlite', // 数据库文件
245
+
246
+ // 其他非代码文件
247
+ 'sh', 'bat', 'cmd', // 脚本文件(通常只审查业务代码)
248
+ 'ps1', // PowerShell 脚本
249
+ 'lock', // 锁文件(如 package-lock.json, yarn.lock)
250
+ 'map', // Source map 文件
251
+ 'log', // 日志文件
252
+ 'bak', 'backup', // 备份文件
253
+ 'tmp', 'temp', // 临时文件
254
+ 'swp', 'swo', // Vim swap 文件
255
+ 'DS_Store', // macOS 文件
256
+ ];
257
+
258
+ // 检查扩展名是否在非代码列表中
259
+ if (nonCodeExtensions.includes(ext)) {
260
+ return true;
261
+ }
262
+
263
+ // 特殊文件名(无扩展名或特殊命名)
264
+ const specialNonCodeFiles = [
265
+ 'LICENSE',
266
+ 'LICENSE.txt',
267
+ 'LICENSE.md',
268
+ 'MIT',
269
+ 'Apache',
270
+ 'GPL',
271
+ 'README',
272
+ 'README.txt',
273
+ 'README.md',
274
+ 'CHANGELOG',
275
+ 'CHANGELOG.md',
276
+ 'CHANGELOG.txt',
277
+ 'CONTRIBUTING',
278
+ 'CONTRIBUTING.md',
279
+ '.gitignore',
280
+ '.gitattributes',
281
+ '.editorconfig',
282
+ '.env',
283
+ '.env.local',
284
+ '.env.development',
285
+ '.env.production',
286
+ '.dockerignore',
287
+ '.eslintrc',
288
+ '.prettierrc',
289
+ '.stylelintrc',
290
+ 'Makefile',
291
+ 'Dockerfile',
292
+ 'docker-compose.yml',
293
+ 'docker-compose.yaml',
294
+ 'Vagrantfile',
295
+ '.travis.yml',
296
+ 'Jenkinsfile',
297
+ ];
298
+
299
+ // 检查是否是特殊非代码文件
300
+ for (const specialFile of specialNonCodeFiles) {
301
+ if (fileName === specialFile || normalizedPath.endsWith('/' + specialFile)) {
302
+ return true;
303
+ }
304
+ }
305
+
306
+ // 检查隐藏文件(以 . 开头的文件,通常是配置文件)
307
+ if (fileName.startsWith('.') && !fileName.startsWith('.claude')) {
308
+ // .claude 目录下的文件可能包含规则配置,需要审查
309
+ return true;
310
+ }
311
+
312
+ return false;
313
+ }
314
+
184
315
  /**
185
316
  * 获取合并请求的diff信息
186
317
  * @param {number} projectId GitLab项目ID
@@ -445,6 +576,7 @@ class GitLabCodeReviewer {
445
576
  const allBlocks = [];
446
577
  const skippedTestFiles = []; // 记录跳过的测试文件
447
578
  const skippedDtoVoFiles = []; // 记录跳过的 DTO/VO 文件
579
+ const skippedNonCodeFiles = []; // 记录跳过的非代码文件
448
580
  for (const diff of diffs) {
449
581
  const filePath = diff.new_path || diff.old_path;
450
582
 
@@ -462,6 +594,13 @@ class GitLabCodeReviewer {
462
594
  continue; // 跳过 DTO/VO 文件
463
595
  }
464
596
 
597
+ // 检查是否是非代码文件
598
+ if (this.isNonCodeFile(filePath)) {
599
+ debugLog(`跳过非代码文件: ${filePath}`);
600
+ skippedNonCodeFiles.push(filePath);
601
+ continue; // 跳过非代码文件
602
+ }
603
+
465
604
  const diffObjects = this.getDiffBlocks(diff);
466
605
  for (let i = 0; i < diffObjects.length; i++) {
467
606
  // 更新块索引
@@ -480,6 +619,11 @@ class GitLabCodeReviewer {
480
619
  infoLog(`已跳过 ${skippedDtoVoFiles.length} 个 DTO/VO 文件: ${skippedDtoVoFiles.join(', ')}`);
481
620
  }
482
621
 
622
+ // 输出跳过的非代码文件统计
623
+ if (skippedNonCodeFiles.length > 0) {
624
+ infoLog(`已跳过 ${skippedNonCodeFiles.length} 个非代码文件: ${skippedNonCodeFiles.join(', ')}`);
625
+ }
626
+
483
627
  // 使用线程池控制并发数量
484
628
  const results = await this.processWithThreadPool(allBlocks, processBlock, maxConcurrency);
485
629
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "job51-gitlab-cr-node-jt-1",
3
- "version": "3.1.0",
3
+ "version": "3.1.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": {