@bernierllc/commit-analyzer 1.0.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.
- package/.eslintrc.cjs +33 -0
- package/LICENSE +21 -0
- package/README.md +146 -0
- package/__tests__/commit-analyzer.test.ts +512 -0
- package/dist/commit-analyzer.d.ts +28 -0
- package/dist/commit-analyzer.js +173 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.js +9 -0
- package/jest.config.cjs +30 -0
- package/package.json +45 -0
- package/src/commit-analyzer.ts +209 -0
- package/src/index.ts +15 -0
- package/src/types.ts +78 -0
- package/tsconfig.json +23 -0
|
@@ -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,173 @@
|
|
|
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 logger = (0, logger_1.createLogger)();
|
|
14
|
+
/**
|
|
15
|
+
* Commit interest analyzer
|
|
16
|
+
*/
|
|
17
|
+
class CommitAnalyzer {
|
|
18
|
+
constructor(criteria = {}) {
|
|
19
|
+
this.criteria = {
|
|
20
|
+
minAdditions: criteria.minAdditions ?? 0,
|
|
21
|
+
minDeletions: criteria.minDeletions ?? 0,
|
|
22
|
+
minTotalChanges: criteria.minTotalChanges ?? 0,
|
|
23
|
+
minFilesChanged: criteria.minFilesChanged ?? 0,
|
|
24
|
+
ignoredBranches: criteria.ignoredBranches,
|
|
25
|
+
ignoredAuthors: criteria.ignoredAuthors,
|
|
26
|
+
filePatterns: criteria.filePatterns,
|
|
27
|
+
requiredFilePatterns: criteria.requiredFilePatterns
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Analyze commit for interest
|
|
32
|
+
*/
|
|
33
|
+
analyze(commit) {
|
|
34
|
+
const reasons = [];
|
|
35
|
+
const matchedCriteria = {};
|
|
36
|
+
let score = 0;
|
|
37
|
+
// Check branch
|
|
38
|
+
if (this.criteria.ignoredBranches?.includes(commit.branch)) {
|
|
39
|
+
reasons.push(`Branch ${commit.branch} is ignored`);
|
|
40
|
+
return {
|
|
41
|
+
interesting: false,
|
|
42
|
+
score: 0,
|
|
43
|
+
reasons,
|
|
44
|
+
matchedCriteria: { branch: false }
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
matchedCriteria.branch = true;
|
|
48
|
+
score += 10;
|
|
49
|
+
// Check author
|
|
50
|
+
const authorEmail = commit.author.email.toLowerCase();
|
|
51
|
+
const authorName = commit.author.name.toLowerCase();
|
|
52
|
+
if (this.criteria.ignoredAuthors?.some(ignored => authorEmail.includes(ignored.toLowerCase()) ||
|
|
53
|
+
authorName.includes(ignored.toLowerCase()))) {
|
|
54
|
+
reasons.push(`Author ${commit.author.email} is ignored`);
|
|
55
|
+
return {
|
|
56
|
+
interesting: false,
|
|
57
|
+
score: 0,
|
|
58
|
+
reasons,
|
|
59
|
+
matchedCriteria: { author: false }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
matchedCriteria.author = true;
|
|
63
|
+
score += 10;
|
|
64
|
+
// Check size
|
|
65
|
+
const totalChanges = commit.additions + commit.deletions;
|
|
66
|
+
const sizeMatch = commit.additions >= this.criteria.minAdditions &&
|
|
67
|
+
commit.deletions >= this.criteria.minDeletions &&
|
|
68
|
+
totalChanges >= this.criteria.minTotalChanges;
|
|
69
|
+
if (sizeMatch) {
|
|
70
|
+
matchedCriteria.size = true;
|
|
71
|
+
score += 30;
|
|
72
|
+
reasons.push(`Size criteria met: +${commit.additions}/-${commit.deletions}`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
matchedCriteria.size = false;
|
|
76
|
+
reasons.push(`Size criteria not met: +${commit.additions}/-${commit.deletions} ` +
|
|
77
|
+
`(required: +${this.criteria.minAdditions}/-${this.criteria.minDeletions}, total: ${this.criteria.minTotalChanges})`);
|
|
78
|
+
}
|
|
79
|
+
// Check files
|
|
80
|
+
const filesMatch = this.checkFiles(commit.files, reasons);
|
|
81
|
+
if (filesMatch) {
|
|
82
|
+
matchedCriteria.files = true;
|
|
83
|
+
score += 30;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
matchedCriteria.files = false;
|
|
87
|
+
}
|
|
88
|
+
// Check file count
|
|
89
|
+
if (commit.files.length >= this.criteria.minFilesChanged) {
|
|
90
|
+
score += 20;
|
|
91
|
+
reasons.push(`File count criteria met: ${commit.files.length} files`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
reasons.push(`File count criteria not met: ${commit.files.length} files ` +
|
|
95
|
+
`(required: ${this.criteria.minFilesChanged})`);
|
|
96
|
+
}
|
|
97
|
+
const interesting = score >= 50 && sizeMatch && filesMatch;
|
|
98
|
+
if (interesting) {
|
|
99
|
+
reasons.unshift('Commit is interesting');
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
reasons.unshift('Commit is not interesting');
|
|
103
|
+
}
|
|
104
|
+
logger.debug('Commit analyzed', {
|
|
105
|
+
sha: commit.sha,
|
|
106
|
+
interesting,
|
|
107
|
+
score,
|
|
108
|
+
reasons: reasons.length
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
interesting,
|
|
112
|
+
score: Math.min(100, score),
|
|
113
|
+
reasons,
|
|
114
|
+
matchedCriteria
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if commit is interesting (quick check)
|
|
119
|
+
*/
|
|
120
|
+
isInteresting(commit) {
|
|
121
|
+
return this.analyze(commit).interesting;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Calculate interest score
|
|
125
|
+
*/
|
|
126
|
+
calculateScore(commit) {
|
|
127
|
+
return this.analyze(commit).score;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Update analysis criteria
|
|
131
|
+
*/
|
|
132
|
+
updateCriteria(criteria) {
|
|
133
|
+
this.criteria = {
|
|
134
|
+
...this.criteria,
|
|
135
|
+
...criteria,
|
|
136
|
+
minAdditions: criteria.minAdditions ?? this.criteria.minAdditions,
|
|
137
|
+
minDeletions: criteria.minDeletions ?? this.criteria.minDeletions,
|
|
138
|
+
minTotalChanges: criteria.minTotalChanges ?? this.criteria.minTotalChanges,
|
|
139
|
+
minFilesChanged: criteria.minFilesChanged ?? this.criteria.minFilesChanged
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check files against patterns
|
|
144
|
+
*/
|
|
145
|
+
checkFiles(files, reasons) {
|
|
146
|
+
// Check required patterns
|
|
147
|
+
if (this.criteria.requiredFilePatterns && this.criteria.requiredFilePatterns.length > 0) {
|
|
148
|
+
const hasRequired = this.criteria.requiredFilePatterns.some(pattern => files.some(file => (0, minimatch_1.minimatch)(file, pattern)));
|
|
149
|
+
if (!hasRequired) {
|
|
150
|
+
reasons.push(`No files match required patterns: ${this.criteria.requiredFilePatterns.join(', ')}`);
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Check include patterns
|
|
155
|
+
if (this.criteria.filePatterns?.include && this.criteria.filePatterns.include.length > 0) {
|
|
156
|
+
const hasIncluded = this.criteria.filePatterns.include.some(pattern => files.some(file => (0, minimatch_1.minimatch)(file, pattern)));
|
|
157
|
+
if (!hasIncluded) {
|
|
158
|
+
reasons.push(`No files match include patterns: ${this.criteria.filePatterns.include.join(', ')}`);
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Check exclude patterns
|
|
163
|
+
if (this.criteria.filePatterns?.exclude && this.criteria.filePatterns.exclude.length > 0) {
|
|
164
|
+
const hasExcluded = this.criteria.filePatterns.exclude.some(pattern => files.some(file => (0, minimatch_1.minimatch)(file, pattern)));
|
|
165
|
+
if (hasExcluded) {
|
|
166
|
+
reasons.push(`Files match exclude patterns: ${this.criteria.filePatterns.exclude.join(', ')}`);
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.CommitAnalyzer = CommitAnalyzer;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
var commit_analyzer_1 = require("./commit-analyzer");
|
|
12
|
+
Object.defineProperty(exports, "CommitAnalyzer", { enumerable: true, get: function () { return commit_analyzer_1.CommitAnalyzer; } });
|
package/dist/types.d.ts
ADDED
|
@@ -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/jest.config.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bernierllc/commit-analyzer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Commit interest analysis and filtering",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"git",
|
|
9
|
+
"commit",
|
|
10
|
+
"analysis",
|
|
11
|
+
"content",
|
|
12
|
+
"filtering"
|
|
13
|
+
],
|
|
14
|
+
"author": "Bernier LLC",
|
|
15
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"minimatch": "^10.0.0",
|
|
18
|
+
"@bernierllc/logger": "1.0.3"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/jest": "^29.5.0",
|
|
22
|
+
"@types/minimatch": "^5.1.0",
|
|
23
|
+
"@types/node": "^20.0.0",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
25
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
26
|
+
"eslint": "^8.0.0",
|
|
27
|
+
"jest": "^29.5.0",
|
|
28
|
+
"rimraf": "^5.0.0",
|
|
29
|
+
"ts-jest": "^29.1.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"test": "jest",
|
|
39
|
+
"test:run": "jest",
|
|
40
|
+
"test:watch": "jest --watch",
|
|
41
|
+
"test:coverage": "jest --coverage",
|
|
42
|
+
"lint": "eslint src --ext .ts",
|
|
43
|
+
"clean": "rimraf dist"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
|