@bernierllc/commit-analyzer 1.6.1 → 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 +8 -0
- package/dist/commit-analyzer.js +53 -3
- package/package.json +2 -2
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
|
package/dist/commit-analyzer.js
CHANGED
|
@@ -10,13 +10,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.CommitAnalyzer = void 0;
|
|
11
11
|
const logger_1 = require("@bernierllc/logger");
|
|
12
12
|
const minimatch_1 = require("minimatch");
|
|
13
|
+
const errors_1 = require("./errors");
|
|
13
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
|
+
}
|
|
14
61
|
/**
|
|
15
62
|
* Commit interest analyzer
|
|
16
63
|
*/
|
|
17
64
|
class CommitAnalyzer {
|
|
18
65
|
criteria;
|
|
19
66
|
constructor(criteria = {}) {
|
|
67
|
+
validateCriteria(criteria);
|
|
20
68
|
this.criteria = {
|
|
21
69
|
minAdditions: criteria.minAdditions ?? 0,
|
|
22
70
|
minDeletions: criteria.minDeletions ?? 0,
|
|
@@ -32,6 +80,7 @@ class CommitAnalyzer {
|
|
|
32
80
|
* Analyze commit for interest
|
|
33
81
|
*/
|
|
34
82
|
analyze(commit) {
|
|
83
|
+
validateCommit(commit);
|
|
35
84
|
const reasons = [];
|
|
36
85
|
const matchedCriteria = {};
|
|
37
86
|
let score = 0;
|
|
@@ -131,6 +180,7 @@ class CommitAnalyzer {
|
|
|
131
180
|
* Update analysis criteria
|
|
132
181
|
*/
|
|
133
182
|
updateCriteria(criteria) {
|
|
183
|
+
validateCriteria(criteria);
|
|
134
184
|
this.criteria = {
|
|
135
185
|
...this.criteria,
|
|
136
186
|
...criteria,
|
|
@@ -146,7 +196,7 @@ class CommitAnalyzer {
|
|
|
146
196
|
checkFiles(files, reasons) {
|
|
147
197
|
// Check required patterns
|
|
148
198
|
if (this.criteria.requiredFilePatterns && this.criteria.requiredFilePatterns.length > 0) {
|
|
149
|
-
const hasRequired = this.criteria.requiredFilePatterns.some(pattern => files.some(file => (
|
|
199
|
+
const hasRequired = this.criteria.requiredFilePatterns.some(pattern => files.some(file => matches(file, pattern)));
|
|
150
200
|
if (!hasRequired) {
|
|
151
201
|
reasons.push(`No files match required patterns: ${this.criteria.requiredFilePatterns.join(', ')}`);
|
|
152
202
|
return false;
|
|
@@ -154,7 +204,7 @@ class CommitAnalyzer {
|
|
|
154
204
|
}
|
|
155
205
|
// Check include patterns
|
|
156
206
|
if (this.criteria.filePatterns?.include && this.criteria.filePatterns.include.length > 0) {
|
|
157
|
-
const hasIncluded = this.criteria.filePatterns.include.some(pattern => files.some(file => (
|
|
207
|
+
const hasIncluded = this.criteria.filePatterns.include.some(pattern => files.some(file => matches(file, pattern)));
|
|
158
208
|
if (!hasIncluded) {
|
|
159
209
|
reasons.push(`No files match include patterns: ${this.criteria.filePatterns.include.join(', ')}`);
|
|
160
210
|
return false;
|
|
@@ -162,7 +212,7 @@ class CommitAnalyzer {
|
|
|
162
212
|
}
|
|
163
213
|
// Check exclude patterns
|
|
164
214
|
if (this.criteria.filePatterns?.exclude && this.criteria.filePatterns.exclude.length > 0) {
|
|
165
|
-
const hasExcluded = this.criteria.filePatterns.exclude.some(pattern => files.some(file => (
|
|
215
|
+
const hasExcluded = this.criteria.filePatterns.exclude.some(pattern => files.some(file => matches(file, pattern)));
|
|
166
216
|
if (hasExcluded) {
|
|
167
217
|
reasons.push(`Files match exclude patterns: ${this.criteria.filePatterns.exclude.join(', ')}`);
|
|
168
218
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bernierllc/commit-analyzer",
|
|
3
|
-
"version": "1.6.
|
|
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": "
|
|
23
|
+
"@bernierllc/logger": "2.0.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/jest": "^29.5.0",
|