@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
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @bernierllc/commit-analyzer
|
|
2
|
+
|
|
3
|
+
Commit interest analysis and filtering
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bernierllc/commit-analyzer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Size-based filtering** - Filter by additions, deletions, total changes
|
|
14
|
+
- **File pattern matching** - Include/exclude files by glob patterns
|
|
15
|
+
- **Branch filtering** - Ignore specific branches
|
|
16
|
+
- **Author filtering** - Ignore specific authors
|
|
17
|
+
- **Interest scoring** - Calculate interest score (0-100)
|
|
18
|
+
- **Configurable criteria** - Dynamic criteria updates
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { CommitAnalyzer } from '@bernierllc/commit-analyzer';
|
|
26
|
+
|
|
27
|
+
const analyzer = new CommitAnalyzer({
|
|
28
|
+
minAdditions: 10,
|
|
29
|
+
minDeletions: 5,
|
|
30
|
+
ignoredBranches: ['develop', 'staging'],
|
|
31
|
+
ignoredAuthors: ['bot@example.com'],
|
|
32
|
+
filePatterns: {
|
|
33
|
+
include: ['src/**/*.ts', 'docs/**/*.md'],
|
|
34
|
+
exclude: ['*.test.ts', '*.spec.ts']
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const commit = {
|
|
39
|
+
sha: 'abc123',
|
|
40
|
+
message: 'Add new feature',
|
|
41
|
+
author: { name: 'Developer', email: 'dev@example.com' },
|
|
42
|
+
branch: 'main',
|
|
43
|
+
additions: 50,
|
|
44
|
+
deletions: 10,
|
|
45
|
+
files: ['src/feature.ts', 'src/utils.ts'],
|
|
46
|
+
timestamp: new Date()
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const result = analyzer.analyze(commit);
|
|
50
|
+
if (result.interesting) {
|
|
51
|
+
console.log('Commit is interesting!', result.reasons);
|
|
52
|
+
console.log('Score:', result.score);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Quick Check
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const isInteresting = analyzer.isInteresting(commit);
|
|
60
|
+
if (isInteresting) {
|
|
61
|
+
// Process commit
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Calculate Score
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const score = analyzer.calculateScore(commit);
|
|
69
|
+
console.log('Interest score:', score); // 0-100
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Update Criteria
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
analyzer.updateCriteria({
|
|
76
|
+
minAdditions: 20,
|
|
77
|
+
minDeletions: 10
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### File Pattern Matching
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const analyzer = new CommitAnalyzer({
|
|
85
|
+
filePatterns: {
|
|
86
|
+
include: ['src/**/*.ts'], // Only TypeScript files
|
|
87
|
+
exclude: ['*.test.ts'] // Exclude test files
|
|
88
|
+
},
|
|
89
|
+
requiredFilePatterns: ['src/**/*.ts'] // Must have TypeScript files
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API
|
|
94
|
+
|
|
95
|
+
### `new CommitAnalyzer(criteria?: CommitAnalysisCriteria)`
|
|
96
|
+
|
|
97
|
+
Creates a new commit analyzer with optional criteria.
|
|
98
|
+
|
|
99
|
+
### `analyzer.analyze(commit: CommitData): CommitAnalysisResult`
|
|
100
|
+
|
|
101
|
+
Analyzes a commit and returns detailed results.
|
|
102
|
+
|
|
103
|
+
### `analyzer.isInteresting(commit: CommitData): boolean`
|
|
104
|
+
|
|
105
|
+
Quick check if a commit is interesting.
|
|
106
|
+
|
|
107
|
+
### `analyzer.calculateScore(commit: CommitData): number`
|
|
108
|
+
|
|
109
|
+
Calculates interest score (0-100).
|
|
110
|
+
|
|
111
|
+
### `analyzer.updateCriteria(criteria: Partial<CommitAnalysisCriteria>): void`
|
|
112
|
+
|
|
113
|
+
Updates analysis criteria dynamically.
|
|
114
|
+
|
|
115
|
+
## Integration Status
|
|
116
|
+
|
|
117
|
+
### Logger Integration
|
|
118
|
+
**Status**: ✅ Integrated
|
|
119
|
+
|
|
120
|
+
Uses `@bernierllc/logger` for analysis events, filtering decisions, and scoring calculations.
|
|
121
|
+
|
|
122
|
+
### NeverHub Integration
|
|
123
|
+
**Status**: ⚠️ Optional
|
|
124
|
+
|
|
125
|
+
Can emit analysis events to NeverHub for distributed monitoring and observability. Commit analyzer can publish events like `commit.analyzed`, `commit.interesting`, and `commit.filtered` to NeverHub when available.
|
|
126
|
+
|
|
127
|
+
**Pattern**: Optional service discovery integration - package can emit analysis events to NeverHub for distributed monitoring.
|
|
128
|
+
|
|
129
|
+
**Example Integration**:
|
|
130
|
+
```typescript
|
|
131
|
+
// If NeverHub is available, emit events
|
|
132
|
+
if (typeof detectNeverHub === 'function') {
|
|
133
|
+
const result = analyzer.analyze(commit);
|
|
134
|
+
neverhub.emit('commit-analyzer.commit.analyzed', result);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Docs-Suite Integration
|
|
139
|
+
**Status**: ✅ Ready
|
|
140
|
+
|
|
141
|
+
TypeDoc-compatible JSDoc comments are included throughout the source code. All public APIs are documented with examples and type information.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Copyright (c) 2025 Bernier LLC. All rights reserved.
|
|
146
|
+
|
|
@@ -0,0 +1,512 @@
|
|
|
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
|
+
|