@bernierllc/commit-analyzer 1.2.5 → 1.4.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.
@@ -15,6 +15,7 @@ const logger = (0, logger_1.createLogger)();
15
15
  * Commit interest analyzer
16
16
  */
17
17
  class CommitAnalyzer {
18
+ criteria;
18
19
  constructor(criteria = {}) {
19
20
  this.criteria = {
20
21
  minAdditions: criteria.minAdditions ?? 0,
@@ -0,0 +1,11 @@
1
+ export type CommitAnalyzerErrorCode = 'COMMIT_ANALYZER_ERROR' | 'COMMIT_ANALYZER_INVALID_CRITERIA' | 'COMMIT_ANALYZER_INVALID_COMMIT' | 'COMMIT_ANALYZER_PATTERN_ERROR';
2
+ export interface CommitAnalyzerErrorOptions {
3
+ cause?: Error;
4
+ code?: CommitAnalyzerErrorCode;
5
+ context?: Record<string, unknown>;
6
+ }
7
+ export declare class CommitAnalyzerError extends Error {
8
+ readonly code: CommitAnalyzerErrorCode;
9
+ readonly context?: Record<string, unknown>;
10
+ constructor(message: string, options?: CommitAnalyzerErrorOptions);
11
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.CommitAnalyzerError = void 0;
11
+ class CommitAnalyzerError extends Error {
12
+ code;
13
+ context;
14
+ constructor(message, options) {
15
+ super(message, options?.cause ? { cause: options.cause } : undefined);
16
+ this.name = 'CommitAnalyzerError';
17
+ this.code = options?.code ?? 'COMMIT_ANALYZER_ERROR';
18
+ if (options?.context !== undefined) {
19
+ this.context = options.context;
20
+ }
21
+ Error.captureStackTrace?.(this, this.constructor);
22
+ }
23
+ }
24
+ exports.CommitAnalyzerError = CommitAnalyzerError;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { CommitAnalyzer } from './commit-analyzer';
2
+ export { CommitAnalyzerError } from './errors';
3
+ export type { CommitAnalyzerErrorCode, CommitAnalyzerErrorOptions } from './errors';
2
4
  export type { CommitData, CommitAnalysisCriteria, CommitAnalysisResult } from './types';
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@ The client may use and modify this code *only within the scope of the project it
7
7
  Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.CommitAnalyzer = void 0;
10
+ exports.CommitAnalyzerError = exports.CommitAnalyzer = void 0;
11
11
  var commit_analyzer_1 = require("./commit-analyzer");
12
12
  Object.defineProperty(exports, "CommitAnalyzer", { enumerable: true, get: function () { return commit_analyzer_1.CommitAnalyzer; } });
13
+ var errors_1 = require("./errors");
14
+ Object.defineProperty(exports, "CommitAnalyzerError", { enumerable: true, get: function () { return errors_1.CommitAnalyzerError; } });
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@bernierllc/commit-analyzer",
3
- "version": "1.2.5",
3
+ "version": "1.4.0",
4
4
  "description": "Commit interest analysis and filtering",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
7
12
  "keywords": [
8
13
  "git",
9
14
  "commit",
package/.eslintrc.cjs DELETED
@@ -1,33 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- module.exports = {
10
- parser: '@typescript-eslint/parser',
11
- extends: [
12
- 'eslint:recommended',
13
- 'plugin:@typescript-eslint/recommended'
14
- ],
15
- plugins: ['@typescript-eslint'],
16
- parserOptions: {
17
- ecmaVersion: 2020,
18
- sourceType: 'module',
19
- project: './tsconfig.json'
20
- },
21
- env: {
22
- node: true,
23
- es6: true
24
- },
25
- rules: {
26
- '@typescript-eslint/explicit-function-return-type': 'off',
27
- '@typescript-eslint/no-explicit-any': 'error',
28
- '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
29
- '@typescript-eslint/no-non-null-assertion': 'warn'
30
- },
31
- ignorePatterns: ['dist/', 'node_modules/', '*.cjs']
32
- };
33
-
package/CHANGELOG.md DELETED
@@ -1,95 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [1.2.5](https://github.com/bernierllc/tools/compare/@bernierllc/commit-analyzer@1.2.4...@bernierllc/commit-analyzer@1.2.5) (2026-05-19)
7
-
8
- **Note:** Version bump only for package @bernierllc/commit-analyzer
9
-
10
-
11
-
12
-
13
-
14
- ## [1.2.4](https://github.com/bernierllc/tools/compare/@bernierllc/commit-analyzer@1.2.3...@bernierllc/commit-analyzer@1.2.4) (2026-05-19)
15
-
16
- **Note:** Version bump only for package @bernierllc/commit-analyzer
17
-
18
-
19
-
20
-
21
-
22
- ## [1.2.3](https://github.com/bernierllc/tools/compare/@bernierllc/commit-analyzer@1.2.2...@bernierllc/commit-analyzer@1.2.3) (2026-03-30)
23
-
24
- **Note:** Version bump only for package @bernierllc/commit-analyzer
25
-
26
-
27
-
28
-
29
-
30
- ## [1.2.2](https://github.com/bernierllc/tools/compare/@bernierllc/commit-analyzer@1.2.1...@bernierllc/commit-analyzer@1.2.2) (2026-03-09)
31
-
32
- **Note:** Version bump only for package @bernierllc/commit-analyzer
33
-
34
-
35
-
36
-
37
-
38
- ## [1.2.1](https://github.com/bernierllc/tools/compare/@bernierllc/commit-analyzer@1.2.0...@bernierllc/commit-analyzer@1.2.1) (2026-03-03)
39
-
40
- **Note:** Version bump only for package @bernierllc/commit-analyzer
41
-
42
-
43
-
44
-
45
-
46
- # 1.2.0 (2025-12-25)
47
-
48
-
49
- ### Bug Fixes
50
-
51
- * **ci:** add lerna version step before publish ([3d20300](https://github.com/bernierllc/tools/commit/3d203002143bf353fffafe4f8a78a99009567347))
52
- * **ci:** fix release workflow + convert internal deps to workspace:* ([01c078b](https://github.com/bernierllc/tools/commit/01c078b49d6025f7eef750f79207a1c71c8d85dc))
53
- * update neverhub-adapter deps to workspace:* and publish 0.1.2 ([f0e3d04](https://github.com/bernierllc/tools/commit/f0e3d04d8d4f094e3bb899ddf81e93243d16e2c2))
54
-
55
-
56
- ### Features
57
-
58
- * add 4 new core packages ([3726d4c](https://github.com/bernierllc/tools/commit/3726d4cc31d60c7c6d65edb526e7e4835287d426))
59
-
60
-
61
-
62
-
63
-
64
- # 1.1.0 (2025-12-25)
65
-
66
-
67
- ### Bug Fixes
68
-
69
- * **ci:** fix release workflow + convert internal deps to workspace:* ([01c078b](https://github.com/bernierllc/tools/commit/01c078b49d6025f7eef750f79207a1c71c8d85dc))
70
- * update neverhub-adapter deps to workspace:* and publish 0.1.2 ([f0e3d04](https://github.com/bernierllc/tools/commit/f0e3d04d8d4f094e3bb899ddf81e93243d16e2c2))
71
-
72
-
73
- ### Features
74
-
75
- * add 4 new core packages ([3726d4c](https://github.com/bernierllc/tools/commit/3726d4cc31d60c7c6d65edb526e7e4835287d426))
76
-
77
-
78
-
79
-
80
-
81
- # @bernierllc/commit-analyzer
82
-
83
- ## 1.0.2
84
-
85
- ### Patch Changes
86
-
87
- - Updated dependencies [[`73c1d1e`](https://github.com/bernierllc/tools/commit/73c1d1e46114cf2ccfd5b74b83743361247f4502)]:
88
- - @bernierllc/logger@1.1.0
89
-
90
- ## 1.0.1
91
-
92
- ### Patch Changes
93
-
94
- - Updated dependencies [[`24899fa`](https://github.com/bernierllc/tools/commit/24899fa4eaf80ae329f7bd74483cf97a132f5d4c)]:
95
- - @bernierllc/logger@1.0.4
@@ -1,512 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { CommitAnalyzer } from '../src';
10
- import type { CommitData } from '../src';
11
-
12
- describe('CommitAnalyzer', () => {
13
- let analyzer: CommitAnalyzer;
14
-
15
- const createCommit = (overrides: Partial<CommitData> = {}): CommitData => ({
16
- sha: 'abc123',
17
- message: 'Test commit',
18
- author: {
19
- name: 'Developer',
20
- email: 'dev@example.com'
21
- },
22
- branch: 'main',
23
- additions: 50,
24
- deletions: 10,
25
- files: ['src/feature.ts', 'src/utils.ts'],
26
- timestamp: new Date(),
27
- ...overrides
28
- });
29
-
30
- beforeEach(() => {
31
- analyzer = new CommitAnalyzer({
32
- minAdditions: 10,
33
- minDeletions: 5,
34
- ignoredBranches: ['develop', 'staging'],
35
- filePatterns: {
36
- include: ['src/**/*.ts'],
37
- exclude: ['*.test.ts']
38
- }
39
- });
40
- });
41
-
42
- describe('constructor', () => {
43
- it('should create analyzer with default criteria', () => {
44
- const defaultAnalyzer = new CommitAnalyzer();
45
- expect(defaultAnalyzer).toBeInstanceOf(CommitAnalyzer);
46
- });
47
-
48
- it('should create analyzer with custom criteria', () => {
49
- expect(analyzer).toBeInstanceOf(CommitAnalyzer);
50
- });
51
-
52
- it('should handle empty criteria object', () => {
53
- const emptyAnalyzer = new CommitAnalyzer({});
54
- expect(emptyAnalyzer).toBeInstanceOf(CommitAnalyzer);
55
- });
56
- });
57
-
58
- describe('analyze', () => {
59
- it('should identify interesting commits', () => {
60
- const commit = createCommit({
61
- additions: 50,
62
- deletions: 10,
63
- files: ['src/feature.ts', 'src/utils.ts']
64
- });
65
-
66
- const result = analyzer.analyze(commit);
67
-
68
- expect(result.interesting).toBe(true);
69
- expect(result.score).toBeGreaterThan(50);
70
- expect(result.reasons[0]).toBe('Commit is interesting');
71
- });
72
-
73
- it('should filter out ignored branches', () => {
74
- const commit = createCommit({ branch: 'develop' });
75
-
76
- const result = analyzer.analyze(commit);
77
-
78
- expect(result.interesting).toBe(false);
79
- expect(result.score).toBe(0);
80
- expect(result.reasons).toContain('Branch develop is ignored');
81
- expect(result.matchedCriteria.branch).toBe(false);
82
- });
83
-
84
- it('should filter out ignored authors by email', () => {
85
- const commit = createCommit({
86
- author: { name: 'Bot', email: 'bot@example.com' }
87
- });
88
-
89
- analyzer = new CommitAnalyzer({
90
- ignoredAuthors: ['bot@example.com']
91
- });
92
-
93
- const result = analyzer.analyze(commit);
94
-
95
- expect(result.interesting).toBe(false);
96
- expect(result.reasons).toContain('Author bot@example.com is ignored');
97
- expect(result.matchedCriteria.author).toBe(false);
98
- });
99
-
100
- it('should filter out ignored authors by name (case insensitive)', () => {
101
- const commit = createCommit({
102
- author: { name: 'Bot User', email: 'user@example.com' }
103
- });
104
-
105
- analyzer = new CommitAnalyzer({
106
- ignoredAuthors: ['bot']
107
- });
108
-
109
- const result = analyzer.analyze(commit);
110
-
111
- expect(result.interesting).toBe(false);
112
- expect(result.matchedCriteria.author).toBe(false);
113
- });
114
-
115
- it('should reject commits not meeting size criteria', () => {
116
- const commit = createCommit({
117
- additions: 5,
118
- deletions: 2
119
- });
120
-
121
- const result = analyzer.analyze(commit);
122
-
123
- expect(result.interesting).toBe(false);
124
- expect(result.matchedCriteria.size).toBe(false);
125
- expect(result.reasons).toContain(
126
- 'Size criteria not met: +5/-2 (required: +10/-5, total: 0)'
127
- );
128
- });
129
-
130
- it('should check minTotalChanges criteria', () => {
131
- const commit = createCommit({
132
- additions: 5,
133
- deletions: 5
134
- });
135
-
136
- analyzer = new CommitAnalyzer({
137
- minTotalChanges: 20
138
- });
139
-
140
- const result = analyzer.analyze(commit);
141
-
142
- expect(result.matchedCriteria.size).toBe(false);
143
- });
144
-
145
- it('should reject commits with excluded file patterns', () => {
146
- analyzer = new CommitAnalyzer({
147
- minAdditions: 10,
148
- minDeletions: 5,
149
- filePatterns: {
150
- include: ['src/**/*.ts'],
151
- exclude: ['**/*.test.ts']
152
- }
153
- });
154
-
155
- const commit = createCommit({
156
- additions: 50,
157
- deletions: 10,
158
- files: ['src/feature.test.ts']
159
- });
160
-
161
- const result = analyzer.analyze(commit);
162
-
163
- expect(result.interesting).toBe(false);
164
- expect(result.matchedCriteria.files).toBe(false);
165
- expect(result.reasons.some(r => r.includes('exclude patterns'))).toBe(true);
166
- });
167
-
168
- it('should reject commits without required file patterns', () => {
169
- const commit = createCommit({
170
- files: ['docs/readme.md']
171
- });
172
-
173
- analyzer = new CommitAnalyzer({
174
- requiredFilePatterns: ['src/**/*.ts']
175
- });
176
-
177
- const result = analyzer.analyze(commit);
178
-
179
- expect(result.interesting).toBe(false);
180
- expect(result.matchedCriteria.files).toBe(false);
181
- expect(result.reasons.some(r => r.includes('required patterns'))).toBe(true);
182
- });
183
-
184
- it('should reject commits without include file patterns', () => {
185
- const commit = createCommit({
186
- files: ['docs/readme.md']
187
- });
188
-
189
- const result = analyzer.analyze(commit);
190
-
191
- expect(result.interesting).toBe(false);
192
- expect(result.matchedCriteria.files).toBe(false);
193
- expect(result.reasons.some(r => r.includes('include patterns'))).toBe(true);
194
- });
195
-
196
- it('should check minFilesChanged criteria', () => {
197
- const commit = createCommit({
198
- files: ['src/one.ts']
199
- });
200
-
201
- analyzer = new CommitAnalyzer({
202
- minFilesChanged: 3
203
- });
204
-
205
- const result = analyzer.analyze(commit);
206
-
207
- expect(result.reasons.some(r => r.includes('File count criteria not met'))).toBe(true);
208
- });
209
-
210
- it('should accept commits meeting minFilesChanged criteria', () => {
211
- const commit = createCommit({
212
- additions: 50,
213
- deletions: 10,
214
- files: ['src/one.ts', 'src/two.ts', 'src/three.ts']
215
- });
216
-
217
- analyzer = new CommitAnalyzer({
218
- minFilesChanged: 3,
219
- minAdditions: 10,
220
- minDeletions: 5,
221
- filePatterns: {
222
- include: ['src/**/*.ts']
223
- }
224
- });
225
-
226
- const result = analyzer.analyze(commit);
227
-
228
- expect(result.reasons.some(r => r.includes('File count criteria met: 3 files'))).toBe(true);
229
- });
230
-
231
- it('should cap score at 100', () => {
232
- const commit = createCommit({
233
- additions: 500,
234
- deletions: 100,
235
- files: ['src/feature.ts', 'src/utils.ts', 'src/helpers.ts']
236
- });
237
-
238
- analyzer = new CommitAnalyzer({
239
- minAdditions: 10,
240
- minDeletions: 5,
241
- minFilesChanged: 2
242
- });
243
-
244
- const result = analyzer.analyze(commit);
245
-
246
- expect(result.score).toBeLessThanOrEqual(100);
247
- });
248
-
249
- it('should handle empty files array', () => {
250
- const commit = createCommit({
251
- files: []
252
- });
253
-
254
- const result = analyzer.analyze(commit);
255
-
256
- expect(result.interesting).toBe(false);
257
- });
258
-
259
- it('should handle commits with only additions', () => {
260
- const commit = createCommit({
261
- additions: 100,
262
- deletions: 0
263
- });
264
-
265
- const result = analyzer.analyze(commit);
266
-
267
- expect(result.matchedCriteria.size).toBe(false); // Doesn't meet minDeletions
268
- });
269
-
270
- it('should handle commits with only deletions', () => {
271
- const commit = createCommit({
272
- additions: 0,
273
- deletions: 100
274
- });
275
-
276
- analyzer = new CommitAnalyzer({
277
- minAdditions: 0,
278
- minDeletions: 10,
279
- filePatterns: {
280
- include: ['src/**/*.ts']
281
- }
282
- });
283
-
284
- const result = analyzer.analyze(commit);
285
-
286
- expect(result.matchedCriteria.size).toBe(true);
287
- });
288
- });
289
-
290
- describe('isInteresting', () => {
291
- it('should return boolean for interesting commit', () => {
292
- const commit = createCommit({
293
- additions: 50,
294
- deletions: 10
295
- });
296
-
297
- const isInteresting = analyzer.isInteresting(commit);
298
-
299
- expect(typeof isInteresting).toBe('boolean');
300
- expect(isInteresting).toBe(true);
301
- });
302
-
303
- it('should return false for uninteresting commit', () => {
304
- const commit = createCommit({
305
- additions: 1,
306
- deletions: 0
307
- });
308
-
309
- const isInteresting = analyzer.isInteresting(commit);
310
-
311
- expect(isInteresting).toBe(false);
312
- });
313
- });
314
-
315
- describe('calculateScore', () => {
316
- it('should calculate score for commit', () => {
317
- const commit = createCommit({
318
- additions: 100,
319
- deletions: 20
320
- });
321
-
322
- const score = analyzer.calculateScore(commit);
323
-
324
- expect(typeof score).toBe('number');
325
- expect(score).toBeGreaterThan(0);
326
- expect(score).toBeLessThanOrEqual(100);
327
- });
328
-
329
- it('should return 0 for ignored branch', () => {
330
- const commit = createCommit({ branch: 'develop' });
331
-
332
- const score = analyzer.calculateScore(commit);
333
-
334
- expect(score).toBe(0);
335
- });
336
- });
337
-
338
- describe('updateCriteria', () => {
339
- it('should update criteria', () => {
340
- const commit = createCommit({
341
- additions: 15,
342
- deletions: 8
343
- });
344
-
345
- // Initially not interesting
346
- let result = analyzer.analyze(commit);
347
- expect(result.interesting).toBe(true);
348
-
349
- // Update criteria
350
- analyzer.updateCriteria({
351
- minAdditions: 100,
352
- minDeletions: 50
353
- });
354
-
355
- // Now not interesting
356
- result = analyzer.analyze(commit);
357
- expect(result.interesting).toBe(false);
358
- expect(result.matchedCriteria.size).toBe(false);
359
- });
360
-
361
- it('should partially update criteria', () => {
362
- analyzer.updateCriteria({
363
- minAdditions: 20
364
- });
365
-
366
- const commit = createCommit({
367
- additions: 15,
368
- deletions: 10
369
- });
370
-
371
- const result = analyzer.analyze(commit);
372
-
373
- expect(result.matchedCriteria.size).toBe(false);
374
- });
375
-
376
- it('should update file patterns', () => {
377
- analyzer.updateCriteria({
378
- filePatterns: {
379
- include: ['docs/**/*.md']
380
- }
381
- });
382
-
383
- const commit = createCommit({
384
- files: ['docs/readme.md']
385
- });
386
-
387
- const result = analyzer.analyze(commit);
388
-
389
- expect(result.matchedCriteria.files).toBe(true);
390
- });
391
-
392
- it('should update ignored branches', () => {
393
- analyzer.updateCriteria({
394
- ignoredBranches: ['feature']
395
- });
396
-
397
- const commit = createCommit({
398
- branch: 'feature'
399
- });
400
-
401
- const result = analyzer.analyze(commit);
402
-
403
- expect(result.interesting).toBe(false);
404
- expect(result.matchedCriteria.branch).toBe(false);
405
- });
406
-
407
- it('should update ignored authors', () => {
408
- analyzer.updateCriteria({
409
- ignoredAuthors: ['renovate']
410
- });
411
-
412
- const commit = createCommit({
413
- author: {
414
- name: 'Renovate Bot',
415
- email: 'renovate@example.com'
416
- }
417
- });
418
-
419
- const result = analyzer.analyze(commit);
420
-
421
- expect(result.interesting).toBe(false);
422
- expect(result.matchedCriteria.author).toBe(false);
423
- });
424
- });
425
-
426
- describe('edge cases', () => {
427
- it('should handle commit with no file patterns configured', () => {
428
- analyzer = new CommitAnalyzer({
429
- minAdditions: 10,
430
- minDeletions: 5
431
- });
432
-
433
- const commit = createCommit({
434
- additions: 50,
435
- deletions: 10
436
- });
437
-
438
- const result = analyzer.analyze(commit);
439
-
440
- // When no file patterns configured, checkFiles returns true, so files will be true
441
- expect(result.matchedCriteria.files).toBe(true);
442
- });
443
-
444
- it('should handle commit with username', () => {
445
- const commit = createCommit({
446
- author: {
447
- name: 'Developer',
448
- email: 'dev@example.com',
449
- username: 'devuser'
450
- }
451
- });
452
-
453
- const result = analyzer.analyze(commit);
454
-
455
- expect(result).toBeDefined();
456
- });
457
-
458
- it('should handle multiple required file patterns', () => {
459
- analyzer = new CommitAnalyzer({
460
- requiredFilePatterns: ['src/**/*.ts', 'docs/**/*.md']
461
- });
462
-
463
- const commit = createCommit({
464
- files: ['src/feature.ts']
465
- });
466
-
467
- const result = analyzer.analyze(commit);
468
-
469
- expect(result.matchedCriteria.files).toBe(true);
470
- });
471
-
472
- it('should handle multiple exclude patterns', () => {
473
- analyzer = new CommitAnalyzer({
474
- minAdditions: 10,
475
- minDeletions: 5,
476
- filePatterns: {
477
- include: ['src/**/*.ts'],
478
- exclude: ['**/*.test.ts', '**/*.spec.ts']
479
- }
480
- });
481
-
482
- const commit = createCommit({
483
- additions: 50,
484
- deletions: 10,
485
- files: ['src/feature.spec.ts']
486
- });
487
-
488
- const result = analyzer.analyze(commit);
489
-
490
- expect(result.interesting).toBe(false);
491
- expect(result.matchedCriteria.files).toBe(false);
492
- });
493
-
494
- it('should handle case-insensitive author matching', () => {
495
- analyzer = new CommitAnalyzer({
496
- ignoredAuthors: ['BOT@EXAMPLE.COM']
497
- });
498
-
499
- const commit = createCommit({
500
- author: {
501
- name: 'Bot User',
502
- email: 'bot@example.com'
503
- }
504
- });
505
-
506
- const result = analyzer.analyze(commit);
507
-
508
- expect(result.interesting).toBe(false);
509
- });
510
- });
511
- });
512
-
package/jest.config.cjs DELETED
@@ -1,30 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- module.exports = {
10
- preset: 'ts-jest',
11
- testEnvironment: '<rootDir>/../../../jest-environment-node-fixed.cjs',
12
- roots: ['<rootDir>/__tests__'],
13
- testMatch: ['**/*.test.ts'],
14
- collectCoverageFrom: [
15
- 'src/**/*.ts',
16
- '!src/**/*.d.ts',
17
- '!src/index.ts'
18
- ],
19
- coverageThreshold: {
20
- global: {
21
- branches: 90,
22
- functions: 90,
23
- lines: 90,
24
- statements: 90
25
- }
26
- },
27
- coverageDirectory: 'coverage',
28
- verbose: true
29
- };
30
-
@@ -1,209 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { createLogger } from '@bernierllc/logger';
10
- import { minimatch } from 'minimatch';
11
- import type {
12
- CommitData,
13
- CommitAnalysisCriteria,
14
- CommitAnalysisResult
15
- } from './types';
16
-
17
- const logger = createLogger();
18
-
19
- /**
20
- * Commit interest analyzer
21
- */
22
- export class CommitAnalyzer {
23
- private criteria: Required<Pick<CommitAnalysisCriteria, 'minAdditions' | 'minDeletions' | 'minTotalChanges' | 'minFilesChanged'>> & Partial<CommitAnalysisCriteria>;
24
-
25
- constructor(criteria: CommitAnalysisCriteria = {}) {
26
- this.criteria = {
27
- minAdditions: criteria.minAdditions ?? 0,
28
- minDeletions: criteria.minDeletions ?? 0,
29
- minTotalChanges: criteria.minTotalChanges ?? 0,
30
- minFilesChanged: criteria.minFilesChanged ?? 0,
31
- ignoredBranches: criteria.ignoredBranches,
32
- ignoredAuthors: criteria.ignoredAuthors,
33
- filePatterns: criteria.filePatterns,
34
- requiredFilePatterns: criteria.requiredFilePatterns
35
- };
36
- }
37
-
38
- /**
39
- * Analyze commit for interest
40
- */
41
- analyze(commit: CommitData): CommitAnalysisResult {
42
- const reasons: string[] = [];
43
- const matchedCriteria: CommitAnalysisResult['matchedCriteria'] = {};
44
- let score = 0;
45
-
46
- // Check branch
47
- if (this.criteria.ignoredBranches?.includes(commit.branch)) {
48
- reasons.push(`Branch ${commit.branch} is ignored`);
49
- return {
50
- interesting: false,
51
- score: 0,
52
- reasons,
53
- matchedCriteria: { branch: false }
54
- };
55
- }
56
- matchedCriteria.branch = true;
57
- score += 10;
58
-
59
- // Check author
60
- const authorEmail = commit.author.email.toLowerCase();
61
- const authorName = commit.author.name.toLowerCase();
62
- if (
63
- this.criteria.ignoredAuthors?.some(
64
- ignored => authorEmail.includes(ignored.toLowerCase()) ||
65
- authorName.includes(ignored.toLowerCase())
66
- )
67
- ) {
68
- reasons.push(`Author ${commit.author.email} is ignored`);
69
- return {
70
- interesting: false,
71
- score: 0,
72
- reasons,
73
- matchedCriteria: { author: false }
74
- };
75
- }
76
- matchedCriteria.author = true;
77
- score += 10;
78
-
79
- // Check size
80
- const totalChanges = commit.additions + commit.deletions;
81
- const sizeMatch =
82
- commit.additions >= this.criteria.minAdditions &&
83
- commit.deletions >= this.criteria.minDeletions &&
84
- totalChanges >= this.criteria.minTotalChanges;
85
-
86
- if (sizeMatch) {
87
- matchedCriteria.size = true;
88
- score += 30;
89
- reasons.push(`Size criteria met: +${commit.additions}/-${commit.deletions}`);
90
- } else {
91
- matchedCriteria.size = false;
92
- reasons.push(
93
- `Size criteria not met: +${commit.additions}/-${commit.deletions} ` +
94
- `(required: +${this.criteria.minAdditions}/-${this.criteria.minDeletions}, total: ${this.criteria.minTotalChanges})`
95
- );
96
- }
97
-
98
- // Check files
99
- const filesMatch = this.checkFiles(commit.files, reasons);
100
- if (filesMatch) {
101
- matchedCriteria.files = true;
102
- score += 30;
103
- } else {
104
- matchedCriteria.files = false;
105
- }
106
-
107
- // Check file count
108
- if (commit.files.length >= this.criteria.minFilesChanged) {
109
- score += 20;
110
- reasons.push(`File count criteria met: ${commit.files.length} files`);
111
- } else {
112
- reasons.push(
113
- `File count criteria not met: ${commit.files.length} files ` +
114
- `(required: ${this.criteria.minFilesChanged})`
115
- );
116
- }
117
-
118
- const interesting = score >= 50 && sizeMatch && filesMatch;
119
-
120
- if (interesting) {
121
- reasons.unshift('Commit is interesting');
122
- } else {
123
- reasons.unshift('Commit is not interesting');
124
- }
125
-
126
- logger.debug('Commit analyzed', {
127
- sha: commit.sha,
128
- interesting,
129
- score,
130
- reasons: reasons.length
131
- });
132
-
133
- return {
134
- interesting,
135
- score: Math.min(100, score),
136
- reasons,
137
- matchedCriteria
138
- };
139
- }
140
-
141
- /**
142
- * Check if commit is interesting (quick check)
143
- */
144
- isInteresting(commit: CommitData): boolean {
145
- return this.analyze(commit).interesting;
146
- }
147
-
148
- /**
149
- * Calculate interest score
150
- */
151
- calculateScore(commit: CommitData): number {
152
- return this.analyze(commit).score;
153
- }
154
-
155
- /**
156
- * Update analysis criteria
157
- */
158
- updateCriteria(criteria: Partial<CommitAnalysisCriteria>): void {
159
- this.criteria = {
160
- ...this.criteria,
161
- ...criteria,
162
- minAdditions: criteria.minAdditions ?? this.criteria.minAdditions,
163
- minDeletions: criteria.minDeletions ?? this.criteria.minDeletions,
164
- minTotalChanges: criteria.minTotalChanges ?? this.criteria.minTotalChanges,
165
- minFilesChanged: criteria.minFilesChanged ?? this.criteria.minFilesChanged
166
- };
167
- }
168
-
169
- /**
170
- * Check files against patterns
171
- */
172
- private checkFiles(files: string[], reasons: string[]): boolean {
173
- // Check required patterns
174
- if (this.criteria.requiredFilePatterns && this.criteria.requiredFilePatterns.length > 0) {
175
- const hasRequired = this.criteria.requiredFilePatterns.some(pattern =>
176
- files.some(file => minimatch(file, pattern))
177
- );
178
- if (!hasRequired) {
179
- reasons.push(`No files match required patterns: ${this.criteria.requiredFilePatterns.join(', ')}`);
180
- return false;
181
- }
182
- }
183
-
184
- // Check include patterns
185
- if (this.criteria.filePatterns?.include && this.criteria.filePatterns.include.length > 0) {
186
- const hasIncluded = this.criteria.filePatterns.include.some(pattern =>
187
- files.some(file => minimatch(file, pattern))
188
- );
189
- if (!hasIncluded) {
190
- reasons.push(`No files match include patterns: ${this.criteria.filePatterns.include.join(', ')}`);
191
- return false;
192
- }
193
- }
194
-
195
- // Check exclude patterns
196
- if (this.criteria.filePatterns?.exclude && this.criteria.filePatterns.exclude.length > 0) {
197
- const hasExcluded = this.criteria.filePatterns.exclude.some(pattern =>
198
- files.some(file => minimatch(file, pattern))
199
- );
200
- if (hasExcluded) {
201
- reasons.push(`Files match exclude patterns: ${this.criteria.filePatterns.exclude.join(', ')}`);
202
- return false;
203
- }
204
- }
205
-
206
- return true;
207
- }
208
- }
209
-
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- export { CommitAnalyzer } from './commit-analyzer';
10
- export type {
11
- CommitData,
12
- CommitAnalysisCriteria,
13
- CommitAnalysisResult
14
- } from './types';
15
-
package/src/types.ts DELETED
@@ -1,78 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- /**
10
- * Commit analysis criteria
11
- */
12
- export interface CommitAnalysisCriteria {
13
- /** Minimum lines added */
14
- minAdditions?: number;
15
- /** Minimum lines deleted */
16
- minDeletions?: number;
17
- /** Minimum total changes */
18
- minTotalChanges?: number;
19
- /** Branches to ignore */
20
- ignoredBranches?: string[];
21
- /** Authors to ignore */
22
- ignoredAuthors?: string[];
23
- /** File patterns to include/exclude */
24
- filePatterns?: {
25
- include?: string[];
26
- exclude?: string[];
27
- };
28
- /** Required file patterns */
29
- requiredFilePatterns?: string[];
30
- /** Minimum number of files changed */
31
- minFilesChanged?: number;
32
- }
33
-
34
- /**
35
- * Commit analysis result
36
- */
37
- export interface CommitAnalysisResult {
38
- /** Whether commit is interesting */
39
- interesting: boolean;
40
- /** Interest score (0-100) */
41
- score: number;
42
- /** Reasons for interest/not-interest */
43
- reasons: string[];
44
- /** Which criteria matched */
45
- matchedCriteria: {
46
- size?: boolean;
47
- files?: boolean;
48
- branch?: boolean;
49
- author?: boolean;
50
- };
51
- }
52
-
53
- /**
54
- * Commit data
55
- */
56
- export interface CommitData {
57
- /** Commit SHA */
58
- sha: string;
59
- /** Commit message */
60
- message: string;
61
- /** Commit author */
62
- author: {
63
- name: string;
64
- email: string;
65
- username?: string;
66
- };
67
- /** Branch name */
68
- branch: string;
69
- /** Lines added */
70
- additions: number;
71
- /** Lines deleted */
72
- deletions: number;
73
- /** Files changed */
74
- files: string[];
75
- /** Commit timestamp */
76
- timestamp: Date;
77
- }
78
-
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": ["ES2020"],
6
- "declaration": true,
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "moduleResolution": "node",
14
- "resolveJsonModule": true,
15
- "noUnusedLocals": true,
16
- "noUnusedParameters": true,
17
- "noImplicitReturns": true,
18
- "noFallthroughCasesInSwitch": true
19
- },
20
- "include": ["src/**/*"],
21
- "exclude": ["node_modules", "dist", "__tests__"]
22
- }
23
-