@bernierllc/commit-analyzer 1.6.2 → 1.6.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/README.md CHANGED
@@ -112,6 +112,14 @@ Calculates interest score (0-100).
112
112
 
113
113
  Updates analysis criteria dynamically.
114
114
 
115
+ ### Errors
116
+
117
+ Invalid input throws `CommitAnalyzerError` with a `code`:
118
+
119
+ - `COMMIT_ANALYZER_INVALID_CRITERIA`: a numeric criterion is negative, `NaN` or infinite (constructor or `updateCriteria`; the old criteria are kept).
120
+ - `COMMIT_ANALYZER_INVALID_COMMIT`: `analyze` got commit data with a missing author, a non-string branch, negative or non-finite counts, or a non-string file; `context.fields` lists them.
121
+ - `COMMIT_ANALYZER_PATTERN_ERROR`: minimatch rejected a file pattern; the minimatch error is the `cause`.
122
+
115
123
  ## Integration Status
116
124
 
117
125
  ### Logger Integration
@@ -0,0 +1,28 @@
1
+ import type { CommitData, CommitAnalysisCriteria, CommitAnalysisResult } from './types';
2
+ /**
3
+ * Commit interest analyzer
4
+ */
5
+ export declare class CommitAnalyzer {
6
+ private criteria;
7
+ constructor(criteria?: CommitAnalysisCriteria);
8
+ /**
9
+ * Analyze commit for interest
10
+ */
11
+ analyze(commit: CommitData): CommitAnalysisResult;
12
+ /**
13
+ * Check if commit is interesting (quick check)
14
+ */
15
+ isInteresting(commit: CommitData): boolean;
16
+ /**
17
+ * Calculate interest score
18
+ */
19
+ calculateScore(commit: CommitData): number;
20
+ /**
21
+ * Update analysis criteria
22
+ */
23
+ updateCriteria(criteria: Partial<CommitAnalysisCriteria>): void;
24
+ /**
25
+ * Check files against patterns
26
+ */
27
+ private checkFiles;
28
+ }
@@ -0,0 +1,224 @@
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.CommitAnalyzer = void 0;
11
+ const logger_1 = require("@bernierllc/logger");
12
+ const minimatch_1 = require("minimatch");
13
+ const errors_1 = require("./errors");
14
+ const logger = (0, logger_1.createLogger)();
15
+ const NUMERIC_CRITERIA = ['minAdditions', 'minDeletions', 'minTotalChanges', 'minFilesChanged'];
16
+ function validateCriteria(criteria) {
17
+ for (const key of NUMERIC_CRITERIA) {
18
+ const value = criteria[key];
19
+ if (value !== undefined && !(Number.isFinite(value) && value >= 0)) {
20
+ throw new errors_1.CommitAnalyzerError(`Criterion ${key} must be a non-negative finite number`, {
21
+ code: 'COMMIT_ANALYZER_INVALID_CRITERIA',
22
+ context: { key, value }
23
+ });
24
+ }
25
+ }
26
+ }
27
+ function validateCommit(commit) {
28
+ const problems = [];
29
+ if (typeof commit?.author?.email !== 'string' || typeof commit.author.name !== 'string')
30
+ problems.push('author.name/email');
31
+ if (typeof commit?.branch !== 'string')
32
+ problems.push('branch');
33
+ if (!Number.isFinite(commit?.additions) || commit.additions < 0)
34
+ problems.push('additions');
35
+ if (!Number.isFinite(commit?.deletions) || commit.deletions < 0)
36
+ problems.push('deletions');
37
+ // Array.from turns sparse-array holes into undefined, which .some() would otherwise skip.
38
+ if (!Array.isArray(commit?.files) || Array.from(commit.files).some(f => typeof f !== 'string'))
39
+ problems.push('files');
40
+ if (problems.length > 0) {
41
+ throw new errors_1.CommitAnalyzerError(`Invalid commit data: ${problems.join(', ')}`, {
42
+ code: 'COMMIT_ANALYZER_INVALID_COMMIT',
43
+ context: { sha: commit?.sha, fields: problems }
44
+ });
45
+ }
46
+ }
47
+ function matches(file, pattern) {
48
+ try {
49
+ return (0, minimatch_1.minimatch)(file, pattern);
50
+ }
51
+ catch (error) {
52
+ // String() because JS callers or deserialized config can pass non-string patterns.
53
+ const shown = String(pattern).slice(0, 100);
54
+ throw new errors_1.CommitAnalyzerError(`Invalid file pattern: ${shown}`, {
55
+ code: 'COMMIT_ANALYZER_PATTERN_ERROR',
56
+ cause: error instanceof Error ? error : new Error(String(error)),
57
+ context: { pattern: shown }
58
+ });
59
+ }
60
+ }
61
+ /**
62
+ * Commit interest analyzer
63
+ */
64
+ class CommitAnalyzer {
65
+ criteria;
66
+ constructor(criteria = {}) {
67
+ validateCriteria(criteria);
68
+ this.criteria = {
69
+ minAdditions: criteria.minAdditions ?? 0,
70
+ minDeletions: criteria.minDeletions ?? 0,
71
+ minTotalChanges: criteria.minTotalChanges ?? 0,
72
+ minFilesChanged: criteria.minFilesChanged ?? 0,
73
+ ignoredBranches: criteria.ignoredBranches,
74
+ ignoredAuthors: criteria.ignoredAuthors,
75
+ filePatterns: criteria.filePatterns,
76
+ requiredFilePatterns: criteria.requiredFilePatterns
77
+ };
78
+ }
79
+ /**
80
+ * Analyze commit for interest
81
+ */
82
+ analyze(commit) {
83
+ validateCommit(commit);
84
+ const reasons = [];
85
+ const matchedCriteria = {};
86
+ let score = 0;
87
+ // Check branch
88
+ if (this.criteria.ignoredBranches?.includes(commit.branch)) {
89
+ reasons.push(`Branch ${commit.branch} is ignored`);
90
+ return {
91
+ interesting: false,
92
+ score: 0,
93
+ reasons,
94
+ matchedCriteria: { branch: false }
95
+ };
96
+ }
97
+ matchedCriteria.branch = true;
98
+ score += 10;
99
+ // Check author
100
+ const authorEmail = commit.author.email.toLowerCase();
101
+ const authorName = commit.author.name.toLowerCase();
102
+ if (this.criteria.ignoredAuthors?.some(ignored => authorEmail.includes(ignored.toLowerCase()) ||
103
+ authorName.includes(ignored.toLowerCase()))) {
104
+ reasons.push(`Author ${commit.author.email} is ignored`);
105
+ return {
106
+ interesting: false,
107
+ score: 0,
108
+ reasons,
109
+ matchedCriteria: { author: false }
110
+ };
111
+ }
112
+ matchedCriteria.author = true;
113
+ score += 10;
114
+ // Check size
115
+ const totalChanges = commit.additions + commit.deletions;
116
+ const sizeMatch = commit.additions >= this.criteria.minAdditions &&
117
+ commit.deletions >= this.criteria.minDeletions &&
118
+ totalChanges >= this.criteria.minTotalChanges;
119
+ if (sizeMatch) {
120
+ matchedCriteria.size = true;
121
+ score += 30;
122
+ reasons.push(`Size criteria met: +${commit.additions}/-${commit.deletions}`);
123
+ }
124
+ else {
125
+ matchedCriteria.size = false;
126
+ reasons.push(`Size criteria not met: +${commit.additions}/-${commit.deletions} ` +
127
+ `(required: +${this.criteria.minAdditions}/-${this.criteria.minDeletions}, total: ${this.criteria.minTotalChanges})`);
128
+ }
129
+ // Check files
130
+ const filesMatch = this.checkFiles(commit.files, reasons);
131
+ if (filesMatch) {
132
+ matchedCriteria.files = true;
133
+ score += 30;
134
+ }
135
+ else {
136
+ matchedCriteria.files = false;
137
+ }
138
+ // Check file count
139
+ if (commit.files.length >= this.criteria.minFilesChanged) {
140
+ score += 20;
141
+ reasons.push(`File count criteria met: ${commit.files.length} files`);
142
+ }
143
+ else {
144
+ reasons.push(`File count criteria not met: ${commit.files.length} files ` +
145
+ `(required: ${this.criteria.minFilesChanged})`);
146
+ }
147
+ const interesting = score >= 50 && sizeMatch && filesMatch;
148
+ if (interesting) {
149
+ reasons.unshift('Commit is interesting');
150
+ }
151
+ else {
152
+ reasons.unshift('Commit is not interesting');
153
+ }
154
+ logger.debug('Commit analyzed', {
155
+ sha: commit.sha,
156
+ interesting,
157
+ score,
158
+ reasons: reasons.length
159
+ });
160
+ return {
161
+ interesting,
162
+ score: Math.min(100, score),
163
+ reasons,
164
+ matchedCriteria
165
+ };
166
+ }
167
+ /**
168
+ * Check if commit is interesting (quick check)
169
+ */
170
+ isInteresting(commit) {
171
+ return this.analyze(commit).interesting;
172
+ }
173
+ /**
174
+ * Calculate interest score
175
+ */
176
+ calculateScore(commit) {
177
+ return this.analyze(commit).score;
178
+ }
179
+ /**
180
+ * Update analysis criteria
181
+ */
182
+ updateCriteria(criteria) {
183
+ validateCriteria(criteria);
184
+ this.criteria = {
185
+ ...this.criteria,
186
+ ...criteria,
187
+ minAdditions: criteria.minAdditions ?? this.criteria.minAdditions,
188
+ minDeletions: criteria.minDeletions ?? this.criteria.minDeletions,
189
+ minTotalChanges: criteria.minTotalChanges ?? this.criteria.minTotalChanges,
190
+ minFilesChanged: criteria.minFilesChanged ?? this.criteria.minFilesChanged
191
+ };
192
+ }
193
+ /**
194
+ * Check files against patterns
195
+ */
196
+ checkFiles(files, reasons) {
197
+ // Check required patterns
198
+ if (this.criteria.requiredFilePatterns && this.criteria.requiredFilePatterns.length > 0) {
199
+ const hasRequired = this.criteria.requiredFilePatterns.some(pattern => files.some(file => matches(file, pattern)));
200
+ if (!hasRequired) {
201
+ reasons.push(`No files match required patterns: ${this.criteria.requiredFilePatterns.join(', ')}`);
202
+ return false;
203
+ }
204
+ }
205
+ // Check include patterns
206
+ if (this.criteria.filePatterns?.include && this.criteria.filePatterns.include.length > 0) {
207
+ const hasIncluded = this.criteria.filePatterns.include.some(pattern => files.some(file => matches(file, pattern)));
208
+ if (!hasIncluded) {
209
+ reasons.push(`No files match include patterns: ${this.criteria.filePatterns.include.join(', ')}`);
210
+ return false;
211
+ }
212
+ }
213
+ // Check exclude patterns
214
+ if (this.criteria.filePatterns?.exclude && this.criteria.filePatterns.exclude.length > 0) {
215
+ const hasExcluded = this.criteria.filePatterns.exclude.some(pattern => files.some(file => matches(file, pattern)));
216
+ if (hasExcluded) {
217
+ reasons.push(`Files match exclude patterns: ${this.criteria.filePatterns.exclude.join(', ')}`);
218
+ return false;
219
+ }
220
+ }
221
+ return true;
222
+ }
223
+ }
224
+ exports.CommitAnalyzer = CommitAnalyzer;
@@ -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;
@@ -0,0 +1,4 @@
1
+ export { CommitAnalyzer } from './commit-analyzer';
2
+ export { CommitAnalyzerError } from './errors';
3
+ export type { CommitAnalyzerErrorCode, CommitAnalyzerErrorOptions } from './errors';
4
+ export type { CommitData, CommitAnalysisCriteria, CommitAnalysisResult } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
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 = exports.CommitAnalyzer = void 0;
11
+ var commit_analyzer_1 = require("./commit-analyzer");
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; } });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Commit analysis criteria
3
+ */
4
+ export interface CommitAnalysisCriteria {
5
+ /** Minimum lines added */
6
+ minAdditions?: number;
7
+ /** Minimum lines deleted */
8
+ minDeletions?: number;
9
+ /** Minimum total changes */
10
+ minTotalChanges?: number;
11
+ /** Branches to ignore */
12
+ ignoredBranches?: string[];
13
+ /** Authors to ignore */
14
+ ignoredAuthors?: string[];
15
+ /** File patterns to include/exclude */
16
+ filePatterns?: {
17
+ include?: string[];
18
+ exclude?: string[];
19
+ };
20
+ /** Required file patterns */
21
+ requiredFilePatterns?: string[];
22
+ /** Minimum number of files changed */
23
+ minFilesChanged?: number;
24
+ }
25
+ /**
26
+ * Commit analysis result
27
+ */
28
+ export interface CommitAnalysisResult {
29
+ /** Whether commit is interesting */
30
+ interesting: boolean;
31
+ /** Interest score (0-100) */
32
+ score: number;
33
+ /** Reasons for interest/not-interest */
34
+ reasons: string[];
35
+ /** Which criteria matched */
36
+ matchedCriteria: {
37
+ size?: boolean;
38
+ files?: boolean;
39
+ branch?: boolean;
40
+ author?: boolean;
41
+ };
42
+ }
43
+ /**
44
+ * Commit data
45
+ */
46
+ export interface CommitData {
47
+ /** Commit SHA */
48
+ sha: string;
49
+ /** Commit message */
50
+ message: string;
51
+ /** Commit author */
52
+ author: {
53
+ name: string;
54
+ email: string;
55
+ username?: string;
56
+ };
57
+ /** Branch name */
58
+ branch: string;
59
+ /** Lines added */
60
+ additions: number;
61
+ /** Lines deleted */
62
+ deletions: number;
63
+ /** Files changed */
64
+ files: string[];
65
+ /** Commit timestamp */
66
+ timestamp: Date;
67
+ }
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
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 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/commit-analyzer",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Commit interest analysis and filtering",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "license": "SEE LICENSE IN LICENSE",
21
21
  "dependencies": {
22
22
  "minimatch": "^10.0.0",
23
- "@bernierllc/logger": "2.0.0"
23
+ "@bernierllc/logger": "2.0.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jest": "^29.5.0",