repo-wrapped 0.0.2
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 +94 -0
- package/dist/cli.js +24 -0
- package/dist/commands/generate.js +95 -0
- package/dist/commands/index.js +24 -0
- package/dist/constants/chronotypes.js +23 -0
- package/dist/constants/colors.js +18 -0
- package/dist/constants/index.js +18 -0
- package/dist/formatters/index.js +17 -0
- package/dist/formatters/timeFormatter.js +29 -0
- package/dist/generators/html/scripts/export.js +125 -0
- package/dist/generators/html/scripts/knowledge.js +120 -0
- package/dist/generators/html/scripts/modal.js +68 -0
- package/dist/generators/html/scripts/navigation.js +156 -0
- package/dist/generators/html/scripts/tabs.js +18 -0
- package/dist/generators/html/scripts/tooltip.js +21 -0
- package/dist/generators/html/styles/achievements.css +387 -0
- package/dist/generators/html/styles/base.css +818 -0
- package/dist/generators/html/styles/components.css +1391 -0
- package/dist/generators/html/styles/knowledge.css +221 -0
- package/dist/generators/html/templates/achievementsSection.js +156 -0
- package/dist/generators/html/templates/commitQualitySection.js +89 -0
- package/dist/generators/html/templates/contributionGraph.js +73 -0
- package/dist/generators/html/templates/impactSection.js +117 -0
- package/dist/generators/html/templates/knowledgeSection.js +226 -0
- package/dist/generators/html/templates/streakSection.js +42 -0
- package/dist/generators/html/templates/timePatternsSection.js +110 -0
- package/dist/generators/html/utils/colorUtils.js +21 -0
- package/dist/generators/html/utils/commitMapBuilder.js +24 -0
- package/dist/generators/html/utils/dateRangeCalculator.js +57 -0
- package/dist/generators/html/utils/developerStatsCalculator.js +29 -0
- package/dist/generators/html/utils/scriptLoader.js +16 -0
- package/dist/generators/html/utils/styleLoader.js +18 -0
- package/dist/generators/html/utils/weekGrouper.js +28 -0
- package/dist/index.js +77 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/achievementDefinitions.js +433 -0
- package/dist/utils/achievementEngine.js +170 -0
- package/dist/utils/commitQualityAnalyzer.js +368 -0
- package/dist/utils/fileHotspotAnalyzer.js +270 -0
- package/dist/utils/gitParser.js +125 -0
- package/dist/utils/htmlGenerator.js +449 -0
- package/dist/utils/impactAnalyzer.js +248 -0
- package/dist/utils/knowledgeDistributionAnalyzer.js +374 -0
- package/dist/utils/matrixGenerator.js +350 -0
- package/dist/utils/slideGenerator.js +313 -0
- package/dist/utils/streakCalculator.js +135 -0
- package/dist/utils/timePatternAnalyzer.js +305 -0
- package/dist/utils/wrappedDisplay.js +115 -0
- package/dist/utils/wrappedGenerator.js +377 -0
- package/dist/utils/wrappedHtmlGenerator.js +552 -0
- package/package.json +55 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getQualityLevel = exports.getQualityRating = exports.analyzeCommitQuality = void 0;
|
|
4
|
+
const CONVENTIONAL_COMMIT_REGEX = /^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?!?:\s.+/;
|
|
5
|
+
const CODE_HYGIENE_PATTERNS = {
|
|
6
|
+
quickFix: /fix(ed)?\s+(typo|spelling|grammar)/i,
|
|
7
|
+
workInProgress: /\bwip\b|work in progress/i,
|
|
8
|
+
oops: /oops|whoops|my bad/i,
|
|
9
|
+
profanity: /\b(damn|shit|fuck|crap)\b/i,
|
|
10
|
+
vague: /^(test|testing|fix|update|change|refactor)s?$/i,
|
|
11
|
+
singleChar: /^.$/
|
|
12
|
+
};
|
|
13
|
+
const ISSUE_PATTERNS = [
|
|
14
|
+
/#\d+/,
|
|
15
|
+
/[A-Z]+-\d+/,
|
|
16
|
+
/closes?\s+#\d+/i,
|
|
17
|
+
/fixes?\s+#\d+/i,
|
|
18
|
+
/resolves?\s+#\d+/i // Resolves #123
|
|
19
|
+
];
|
|
20
|
+
const IMPERATIVE_STARTERS = [
|
|
21
|
+
'add', 'fix', 'update', 'remove', 'delete', 'create', 'implement', 'refactor',
|
|
22
|
+
'improve', 'optimize', 'enhance', 'change', 'move', 'rename', 'extract',
|
|
23
|
+
'merge', 'bump', 'revert', 'document', 'test', 'upgrade', 'downgrade'
|
|
24
|
+
];
|
|
25
|
+
function analyzeCommitQuality(commits, options = {}) {
|
|
26
|
+
const { skipBodyCheck = false } = options;
|
|
27
|
+
if (commits.length === 0) {
|
|
28
|
+
return getEmptyQuality();
|
|
29
|
+
}
|
|
30
|
+
let totalSubjectLength = 0;
|
|
31
|
+
let tooShort = 0;
|
|
32
|
+
let tooLong = 0;
|
|
33
|
+
let withPeriod = 0;
|
|
34
|
+
let imperativeMood = 0;
|
|
35
|
+
let withBody = 0;
|
|
36
|
+
let totalBodyLength = 0;
|
|
37
|
+
let wellFormattedBody = 0;
|
|
38
|
+
let conventionalCount = 0;
|
|
39
|
+
let withIssueRef = 0;
|
|
40
|
+
let totalIssueRefs = 0;
|
|
41
|
+
const typeMap = new Map();
|
|
42
|
+
const scopeSet = new Set();
|
|
43
|
+
let breakingChanges = 0;
|
|
44
|
+
// Code hygiene metrics
|
|
45
|
+
let quickFix = 0;
|
|
46
|
+
let workInProgress = 0;
|
|
47
|
+
let oops = 0;
|
|
48
|
+
let profanity = 0;
|
|
49
|
+
let vague = 0;
|
|
50
|
+
let singleChar = 0;
|
|
51
|
+
commits.forEach(commit => {
|
|
52
|
+
const lines = commit.message.split('\n').map(l => l.trim()).filter(l => l);
|
|
53
|
+
const subject = lines[0] || '';
|
|
54
|
+
const body = lines.slice(1).join('\n').trim();
|
|
55
|
+
// Subject analysis
|
|
56
|
+
totalSubjectLength += subject.length;
|
|
57
|
+
if (subject.length < 10)
|
|
58
|
+
tooShort++;
|
|
59
|
+
if (subject.length > 72)
|
|
60
|
+
tooLong++;
|
|
61
|
+
if (subject.endsWith('.'))
|
|
62
|
+
withPeriod++;
|
|
63
|
+
if (startsWithImperative(subject))
|
|
64
|
+
imperativeMood++;
|
|
65
|
+
// Body analysis
|
|
66
|
+
if (body.length > 20) {
|
|
67
|
+
withBody++;
|
|
68
|
+
totalBodyLength += body.length;
|
|
69
|
+
if (isWellFormatted(body))
|
|
70
|
+
wellFormattedBody++;
|
|
71
|
+
}
|
|
72
|
+
// Conventional commits
|
|
73
|
+
const conventionalMatch = subject.match(CONVENTIONAL_COMMIT_REGEX);
|
|
74
|
+
if (conventionalMatch) {
|
|
75
|
+
conventionalCount++;
|
|
76
|
+
const type = conventionalMatch[1];
|
|
77
|
+
typeMap.set(type, (typeMap.get(type) || 0) + 1);
|
|
78
|
+
const scope = conventionalMatch[2];
|
|
79
|
+
if (scope) {
|
|
80
|
+
scopeSet.add(scope.replace(/[()]/g, ''));
|
|
81
|
+
}
|
|
82
|
+
if (conventionalMatch[0].includes('!') || body.toLowerCase().includes('breaking change')) {
|
|
83
|
+
breakingChanges++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Issue references
|
|
87
|
+
const issueRefs = countIssueReferences(commit.message);
|
|
88
|
+
if (issueRefs > 0) {
|
|
89
|
+
withIssueRef++;
|
|
90
|
+
totalIssueRefs += issueRefs;
|
|
91
|
+
}
|
|
92
|
+
// Code hygiene patterns
|
|
93
|
+
if (CODE_HYGIENE_PATTERNS.quickFix.test(commit.message))
|
|
94
|
+
quickFix++;
|
|
95
|
+
if (CODE_HYGIENE_PATTERNS.workInProgress.test(commit.message))
|
|
96
|
+
workInProgress++;
|
|
97
|
+
if (CODE_HYGIENE_PATTERNS.oops.test(commit.message))
|
|
98
|
+
oops++;
|
|
99
|
+
if (CODE_HYGIENE_PATTERNS.profanity.test(commit.message))
|
|
100
|
+
profanity++;
|
|
101
|
+
if (CODE_HYGIENE_PATTERNS.vague.test(subject))
|
|
102
|
+
vague++;
|
|
103
|
+
if (CODE_HYGIENE_PATTERNS.singleChar.test(subject))
|
|
104
|
+
singleChar++;
|
|
105
|
+
});
|
|
106
|
+
// Calculate scores
|
|
107
|
+
const avgSubjectLength = totalSubjectLength / commits.length;
|
|
108
|
+
const subjectScore = calculateSubjectScore(avgSubjectLength, tooShort, tooLong, withPeriod, imperativeMood, commits.length);
|
|
109
|
+
const avgBodyLength = withBody > 0 ? totalBodyLength / withBody : 0;
|
|
110
|
+
const bodyScore = skipBodyCheck ? 10 : calculateBodyScore(withBody, wellFormattedBody, commits.length);
|
|
111
|
+
const conventionAdherence = (conventionalCount / commits.length) * 100;
|
|
112
|
+
const conventionScore = (conventionAdherence / 10);
|
|
113
|
+
const issueRefScore = (withIssueRef / commits.length) * 10;
|
|
114
|
+
const overallScore = (subjectScore + bodyScore + conventionScore + issueRefScore) / 4;
|
|
115
|
+
// Type distribution
|
|
116
|
+
const typeDistribution = {
|
|
117
|
+
features: typeMap.get('feat') || 0,
|
|
118
|
+
fixes: typeMap.get('fix') || 0,
|
|
119
|
+
docs: typeMap.get('docs') || 0,
|
|
120
|
+
refactors: typeMap.get('refactor') || 0,
|
|
121
|
+
tests: typeMap.get('test') || 0,
|
|
122
|
+
chores: typeMap.get('chore') || 0,
|
|
123
|
+
other: commits.length - conventionalCount
|
|
124
|
+
};
|
|
125
|
+
// Generate improvements
|
|
126
|
+
const improvements = generateRecommendations({
|
|
127
|
+
totalCommits: commits.length,
|
|
128
|
+
withBody,
|
|
129
|
+
conventionAdherence,
|
|
130
|
+
tooLong,
|
|
131
|
+
withIssueRef,
|
|
132
|
+
typeDistribution,
|
|
133
|
+
skipBodyCheck
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
overallScore,
|
|
137
|
+
totalCommits: commits.length,
|
|
138
|
+
subjectQuality: {
|
|
139
|
+
score: subjectScore,
|
|
140
|
+
avgLength: Math.round(avgSubjectLength),
|
|
141
|
+
tooShort,
|
|
142
|
+
tooLong,
|
|
143
|
+
withPeriod,
|
|
144
|
+
imperativeMood
|
|
145
|
+
},
|
|
146
|
+
bodyQuality: {
|
|
147
|
+
score: bodyScore,
|
|
148
|
+
withBody,
|
|
149
|
+
avgBodyLength: Math.round(avgBodyLength),
|
|
150
|
+
wellFormatted: wellFormattedBody
|
|
151
|
+
},
|
|
152
|
+
conventionalCommits: {
|
|
153
|
+
adherence: conventionAdherence,
|
|
154
|
+
types: Object.fromEntries(typeMap),
|
|
155
|
+
scopes: Array.from(scopeSet),
|
|
156
|
+
breakingChanges
|
|
157
|
+
},
|
|
158
|
+
issueReferences: {
|
|
159
|
+
withReferences: withIssueRef,
|
|
160
|
+
patterns: extractIssuePatterns(commits),
|
|
161
|
+
avgReferencesPerCommit: totalIssueRefs / commits.length
|
|
162
|
+
},
|
|
163
|
+
codeHygiene: {
|
|
164
|
+
quickFixes: quickFix,
|
|
165
|
+
workInProgress,
|
|
166
|
+
oops,
|
|
167
|
+
profanity,
|
|
168
|
+
vague,
|
|
169
|
+
singleChar
|
|
170
|
+
},
|
|
171
|
+
typeDistribution,
|
|
172
|
+
improvements
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
exports.analyzeCommitQuality = analyzeCommitQuality;
|
|
176
|
+
function startsWithImperative(subject) {
|
|
177
|
+
const firstWord = subject.toLowerCase().split(/[\s:(]/)[0];
|
|
178
|
+
// Check conventional commit prefix
|
|
179
|
+
if (CONVENTIONAL_COMMIT_REGEX.test(subject)) {
|
|
180
|
+
const afterColon = subject.split(':')[1]?.trim().toLowerCase();
|
|
181
|
+
if (afterColon) {
|
|
182
|
+
const afterColonFirstWord = afterColon.split(/[\s:(]/)[0];
|
|
183
|
+
return IMPERATIVE_STARTERS.includes(afterColonFirstWord);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return IMPERATIVE_STARTERS.includes(firstWord);
|
|
187
|
+
}
|
|
188
|
+
function isWellFormatted(body) {
|
|
189
|
+
const lines = body.split('\n');
|
|
190
|
+
// Check if most lines are under 80 characters
|
|
191
|
+
const longLines = lines.filter(l => l.length > 80).length;
|
|
192
|
+
const wellFormattedRatio = 1 - (longLines / lines.length);
|
|
193
|
+
// Check for proper paragraphs (blank lines between sections)
|
|
194
|
+
const hasProperParagraphs = body.includes('\n\n');
|
|
195
|
+
return wellFormattedRatio >= 0.8 || hasProperParagraphs;
|
|
196
|
+
}
|
|
197
|
+
function countIssueReferences(message) {
|
|
198
|
+
let count = 0;
|
|
199
|
+
ISSUE_PATTERNS.forEach(pattern => {
|
|
200
|
+
const matches = message.match(new RegExp(pattern, 'g'));
|
|
201
|
+
if (matches)
|
|
202
|
+
count += matches.length;
|
|
203
|
+
});
|
|
204
|
+
return count;
|
|
205
|
+
}
|
|
206
|
+
function extractIssuePatterns(commits) {
|
|
207
|
+
const patterns = new Set();
|
|
208
|
+
commits.forEach(commit => {
|
|
209
|
+
ISSUE_PATTERNS.forEach(pattern => {
|
|
210
|
+
const matches = commit.message.match(new RegExp(pattern, 'g'));
|
|
211
|
+
if (matches) {
|
|
212
|
+
matches.forEach(match => patterns.add(match));
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
return Array.from(patterns).slice(0, 10); // Return top 10 patterns
|
|
217
|
+
}
|
|
218
|
+
function calculateSubjectScore(avgLength, tooShort, tooLong, withPeriod, imperativeMood, total) {
|
|
219
|
+
let score = 10;
|
|
220
|
+
// Length penalty
|
|
221
|
+
if (avgLength < 20)
|
|
222
|
+
score -= 1;
|
|
223
|
+
if (avgLength > 60)
|
|
224
|
+
score -= 1;
|
|
225
|
+
// Too short/long penalty
|
|
226
|
+
const tooShortRatio = tooShort / total;
|
|
227
|
+
const tooLongRatio = tooLong / total;
|
|
228
|
+
score -= tooShortRatio * 2;
|
|
229
|
+
score -= tooLongRatio * 2;
|
|
230
|
+
// Period penalty
|
|
231
|
+
const periodRatio = withPeriod / total;
|
|
232
|
+
score -= periodRatio * 1;
|
|
233
|
+
// Imperative mood bonus
|
|
234
|
+
const imperativeRatio = imperativeMood / total;
|
|
235
|
+
if (imperativeRatio < 0.5)
|
|
236
|
+
score -= 2;
|
|
237
|
+
else if (imperativeRatio < 0.7)
|
|
238
|
+
score -= 1;
|
|
239
|
+
return Math.max(0, Math.min(10, score));
|
|
240
|
+
}
|
|
241
|
+
function calculateBodyScore(withBody, wellFormatted, total) {
|
|
242
|
+
const bodyRatio = withBody / total;
|
|
243
|
+
const formattedRatio = withBody > 0 ? wellFormatted / withBody : 0;
|
|
244
|
+
let score = 0;
|
|
245
|
+
// Body presence (up to 6 points)
|
|
246
|
+
score += bodyRatio * 6;
|
|
247
|
+
// Formatting quality (up to 4 points)
|
|
248
|
+
score += formattedRatio * 4;
|
|
249
|
+
return Math.max(0, Math.min(10, score));
|
|
250
|
+
}
|
|
251
|
+
function generateRecommendations(data) {
|
|
252
|
+
const tips = [];
|
|
253
|
+
// Body recommendations (skip if body check is disabled)
|
|
254
|
+
if (!data.skipBodyCheck) {
|
|
255
|
+
const bodyRatio = data.withBody / data.totalCommits;
|
|
256
|
+
if (bodyRatio < 0.3) {
|
|
257
|
+
tips.push('Add commit bodies to explain "why" not just "what"');
|
|
258
|
+
}
|
|
259
|
+
else if (bodyRatio < 0.5) {
|
|
260
|
+
tips.push('Try adding more detailed commit descriptions');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Convention recommendations
|
|
264
|
+
if (data.conventionAdherence < 50) {
|
|
265
|
+
tips.push('Consider adopting Conventional Commits format');
|
|
266
|
+
}
|
|
267
|
+
else if (data.conventionAdherence < 70) {
|
|
268
|
+
tips.push('Increase conventional commit usage for better changelog generation');
|
|
269
|
+
}
|
|
270
|
+
// Length recommendations
|
|
271
|
+
if (data.tooLong > data.totalCommits * 0.1) {
|
|
272
|
+
tips.push('Keep subject lines under 72 characters');
|
|
273
|
+
}
|
|
274
|
+
// Issue reference recommendations
|
|
275
|
+
const issueRefRatio = data.withIssueRef / data.totalCommits;
|
|
276
|
+
if (issueRefRatio < 0.3) {
|
|
277
|
+
tips.push('Link commits to issues/tickets for better traceability');
|
|
278
|
+
}
|
|
279
|
+
// Test recommendations
|
|
280
|
+
const testRatio = data.typeDistribution.tests / data.totalCommits;
|
|
281
|
+
if (testRatio < 0.05) {
|
|
282
|
+
tips.push('Add more test commits - aim for 10-15% test coverage');
|
|
283
|
+
}
|
|
284
|
+
// Refactor recommendations
|
|
285
|
+
const refactorRatio = data.typeDistribution.refactors / data.totalCommits;
|
|
286
|
+
if (refactorRatio < 0.05) {
|
|
287
|
+
tips.push('Schedule regular refactoring - aim for 10-15% refactor commits');
|
|
288
|
+
}
|
|
289
|
+
// Balance recommendations
|
|
290
|
+
const featureFixRatio = data.typeDistribution.features / (data.typeDistribution.fixes || 1);
|
|
291
|
+
if (featureFixRatio > 3) {
|
|
292
|
+
tips.push('High feature/fix ratio - consider addressing technical debt');
|
|
293
|
+
}
|
|
294
|
+
return tips;
|
|
295
|
+
}
|
|
296
|
+
function getEmptyQuality() {
|
|
297
|
+
return {
|
|
298
|
+
overallScore: 0,
|
|
299
|
+
totalCommits: 0,
|
|
300
|
+
subjectQuality: {
|
|
301
|
+
score: 0,
|
|
302
|
+
avgLength: 0,
|
|
303
|
+
tooShort: 0,
|
|
304
|
+
tooLong: 0,
|
|
305
|
+
withPeriod: 0,
|
|
306
|
+
imperativeMood: 0
|
|
307
|
+
},
|
|
308
|
+
bodyQuality: {
|
|
309
|
+
score: 0,
|
|
310
|
+
withBody: 0,
|
|
311
|
+
avgBodyLength: 0,
|
|
312
|
+
wellFormatted: 0
|
|
313
|
+
},
|
|
314
|
+
conventionalCommits: {
|
|
315
|
+
adherence: 0,
|
|
316
|
+
types: {},
|
|
317
|
+
scopes: [],
|
|
318
|
+
breakingChanges: 0
|
|
319
|
+
},
|
|
320
|
+
issueReferences: {
|
|
321
|
+
withReferences: 0,
|
|
322
|
+
patterns: [],
|
|
323
|
+
avgReferencesPerCommit: 0
|
|
324
|
+
},
|
|
325
|
+
codeHygiene: {
|
|
326
|
+
quickFixes: 0,
|
|
327
|
+
workInProgress: 0,
|
|
328
|
+
oops: 0,
|
|
329
|
+
profanity: 0,
|
|
330
|
+
vague: 0,
|
|
331
|
+
singleChar: 0
|
|
332
|
+
},
|
|
333
|
+
typeDistribution: {
|
|
334
|
+
features: 0,
|
|
335
|
+
fixes: 0,
|
|
336
|
+
docs: 0,
|
|
337
|
+
refactors: 0,
|
|
338
|
+
tests: 0,
|
|
339
|
+
chores: 0,
|
|
340
|
+
other: 0
|
|
341
|
+
},
|
|
342
|
+
improvements: []
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function getQualityRating(score) {
|
|
346
|
+
if (score >= 9)
|
|
347
|
+
return '⭐⭐⭐⭐⭐';
|
|
348
|
+
if (score >= 7.5)
|
|
349
|
+
return '⭐⭐⭐⭐';
|
|
350
|
+
if (score >= 6)
|
|
351
|
+
return '⭐⭐⭐';
|
|
352
|
+
if (score >= 4)
|
|
353
|
+
return '⭐⭐';
|
|
354
|
+
return '⭐';
|
|
355
|
+
}
|
|
356
|
+
exports.getQualityRating = getQualityRating;
|
|
357
|
+
function getQualityLevel(score) {
|
|
358
|
+
if (score >= 9)
|
|
359
|
+
return 'Excellent';
|
|
360
|
+
if (score >= 7.5)
|
|
361
|
+
return 'Good';
|
|
362
|
+
if (score >= 6)
|
|
363
|
+
return 'Fair';
|
|
364
|
+
if (score >= 4)
|
|
365
|
+
return 'Needs Improvement';
|
|
366
|
+
return 'Poor';
|
|
367
|
+
}
|
|
368
|
+
exports.getQualityLevel = getQualityLevel;
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOwnershipIcon = exports.getRiskLevelColor = exports.analyzeFileHotspots = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
function analyzeFileHotspots(repoPath, startDate, endDate) {
|
|
6
|
+
try {
|
|
7
|
+
// Get file changes with author info from git log
|
|
8
|
+
const since = startDate.toISOString().split('T')[0];
|
|
9
|
+
const until = endDate.toISOString().split('T')[0];
|
|
10
|
+
let gitLog;
|
|
11
|
+
try {
|
|
12
|
+
gitLog = (0, child_process_1.execSync)(`git log --name-only --format="%H|%an|%ad" --date=short --since="${since}" --until="${until}"`, { cwd: repoPath, encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 }).trim();
|
|
13
|
+
}
|
|
14
|
+
catch (gitError) {
|
|
15
|
+
// Git command failed, likely not in a git repo or no commits in range
|
|
16
|
+
return getEmptyAnalysis();
|
|
17
|
+
}
|
|
18
|
+
if (!gitLog) {
|
|
19
|
+
return getEmptyAnalysis();
|
|
20
|
+
}
|
|
21
|
+
// Parse git log output
|
|
22
|
+
const fileMap = new Map();
|
|
23
|
+
const lines = gitLog.split('\n');
|
|
24
|
+
let currentCommit = null;
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
const trimmed = line.trim();
|
|
27
|
+
if (trimmed.includes('|')) {
|
|
28
|
+
// Commit header line
|
|
29
|
+
const [hash, author, date] = trimmed.split('|');
|
|
30
|
+
currentCommit = { hash, author, date };
|
|
31
|
+
}
|
|
32
|
+
else if (trimmed && currentCommit) {
|
|
33
|
+
// File path line
|
|
34
|
+
const filePath = trimmed;
|
|
35
|
+
// Skip binary files, lock files, and common generated files
|
|
36
|
+
if (shouldIgnoreFile(filePath)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!fileMap.has(filePath)) {
|
|
40
|
+
fileMap.set(filePath, {
|
|
41
|
+
path: filePath,
|
|
42
|
+
changeCount: 0,
|
|
43
|
+
authors: [],
|
|
44
|
+
authorDistribution: {},
|
|
45
|
+
firstChange: new Date(currentCommit.date),
|
|
46
|
+
lastChange: new Date(currentCommit.date),
|
|
47
|
+
complexityScore: 0
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const fileStats = fileMap.get(filePath);
|
|
51
|
+
fileStats.changeCount++;
|
|
52
|
+
// Track authors
|
|
53
|
+
if (!fileStats.authors.includes(currentCommit.author)) {
|
|
54
|
+
fileStats.authors.push(currentCommit.author);
|
|
55
|
+
}
|
|
56
|
+
fileStats.authorDistribution[currentCommit.author] =
|
|
57
|
+
(fileStats.authorDistribution[currentCommit.author] || 0) + 1;
|
|
58
|
+
// Update dates
|
|
59
|
+
const commitDate = new Date(currentCommit.date);
|
|
60
|
+
if (commitDate < fileStats.firstChange) {
|
|
61
|
+
fileStats.firstChange = commitDate;
|
|
62
|
+
}
|
|
63
|
+
if (commitDate > fileStats.lastChange) {
|
|
64
|
+
fileStats.lastChange = commitDate;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Calculate complexity scores
|
|
69
|
+
for (const fileStats of fileMap.values()) {
|
|
70
|
+
fileStats.complexityScore = calculateComplexityScore(fileStats);
|
|
71
|
+
}
|
|
72
|
+
// Get top files
|
|
73
|
+
const topFiles = Array.from(fileMap.values())
|
|
74
|
+
.sort((a, b) => b.changeCount - a.changeCount)
|
|
75
|
+
.slice(0, 20);
|
|
76
|
+
// Analyze directories
|
|
77
|
+
const topDirectories = analyzeDirectories(fileMap);
|
|
78
|
+
// Identify technical debt
|
|
79
|
+
const technicalDebt = identifyTechnicalDebt(Array.from(fileMap.values()));
|
|
80
|
+
// Analyze ownership risks
|
|
81
|
+
const ownershipRisks = analyzeOwnership(Array.from(fileMap.values()));
|
|
82
|
+
return {
|
|
83
|
+
topFiles,
|
|
84
|
+
topDirectories,
|
|
85
|
+
technicalDebt,
|
|
86
|
+
ownershipRisks,
|
|
87
|
+
totalFilesAnalyzed: fileMap.size
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('Error analyzing file hotspots:', error);
|
|
92
|
+
return getEmptyAnalysis();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.analyzeFileHotspots = analyzeFileHotspots;
|
|
96
|
+
function shouldIgnoreFile(path) {
|
|
97
|
+
const ignoredExtensions = ['.lock', '.log', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.ttf', '.eot'];
|
|
98
|
+
const ignoredPatterns = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'node_modules/', 'dist/', 'build/', '.next/', 'coverage/'];
|
|
99
|
+
// Check extensions
|
|
100
|
+
if (ignoredExtensions.some(ext => path.toLowerCase().endsWith(ext))) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
// Check patterns
|
|
104
|
+
if (ignoredPatterns.some(pattern => path.includes(pattern))) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
function calculateComplexityScore(fileStats) {
|
|
110
|
+
let score = 0;
|
|
111
|
+
// High churn
|
|
112
|
+
if (fileStats.changeCount > 100)
|
|
113
|
+
score += 3;
|
|
114
|
+
else if (fileStats.changeCount > 50)
|
|
115
|
+
score += 2;
|
|
116
|
+
else if (fileStats.changeCount > 25)
|
|
117
|
+
score += 1;
|
|
118
|
+
// Many authors
|
|
119
|
+
if (fileStats.authors.length > 10)
|
|
120
|
+
score += 2;
|
|
121
|
+
else if (fileStats.authors.length > 5)
|
|
122
|
+
score += 1;
|
|
123
|
+
// Time since last change (older = potentially more stable, but also potentially abandoned)
|
|
124
|
+
const daysSinceLastChange = Math.floor((Date.now() - fileStats.lastChange.getTime()) / (1000 * 60 * 60 * 24));
|
|
125
|
+
if (daysSinceLastChange > 180)
|
|
126
|
+
score += 1; // No changes in 6 months
|
|
127
|
+
return Math.min(10, score);
|
|
128
|
+
}
|
|
129
|
+
function analyzeDirectories(fileMap) {
|
|
130
|
+
const dirMap = new Map();
|
|
131
|
+
// Group files by directory
|
|
132
|
+
for (const file of fileMap.values()) {
|
|
133
|
+
const dirPath = file.path.includes('/')
|
|
134
|
+
? file.path.substring(0, file.path.lastIndexOf('/'))
|
|
135
|
+
: '.';
|
|
136
|
+
if (!dirMap.has(dirPath)) {
|
|
137
|
+
dirMap.set(dirPath, { files: [], totalChanges: 0 });
|
|
138
|
+
}
|
|
139
|
+
const dirStats = dirMap.get(dirPath);
|
|
140
|
+
dirStats.files.push(file);
|
|
141
|
+
dirStats.totalChanges += file.changeCount;
|
|
142
|
+
}
|
|
143
|
+
// Create directory stats
|
|
144
|
+
const directories = [];
|
|
145
|
+
for (const [path, data] of dirMap) {
|
|
146
|
+
const mostActive = data.files.sort((a, b) => b.changeCount - a.changeCount)[0];
|
|
147
|
+
directories.push({
|
|
148
|
+
path,
|
|
149
|
+
totalChanges: data.totalChanges,
|
|
150
|
+
fileCount: data.files.length,
|
|
151
|
+
avgChangesPerFile: data.totalChanges / data.files.length,
|
|
152
|
+
mostActiveFile: mostActive.path
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return directories
|
|
156
|
+
.sort((a, b) => b.totalChanges - a.totalChanges)
|
|
157
|
+
.slice(0, 10);
|
|
158
|
+
}
|
|
159
|
+
function identifyTechnicalDebt(files) {
|
|
160
|
+
const debtFiles = [];
|
|
161
|
+
for (const file of files) {
|
|
162
|
+
const score = file.complexityScore;
|
|
163
|
+
// Only flag files with complexity score >= 4
|
|
164
|
+
if (score < 4)
|
|
165
|
+
continue;
|
|
166
|
+
let riskLevel = 'low';
|
|
167
|
+
if (score >= 8)
|
|
168
|
+
riskLevel = 'critical';
|
|
169
|
+
else if (score >= 6)
|
|
170
|
+
riskLevel = 'high';
|
|
171
|
+
else if (score >= 4)
|
|
172
|
+
riskLevel = 'medium';
|
|
173
|
+
const recommendations = [];
|
|
174
|
+
if (file.changeCount > 50) {
|
|
175
|
+
recommendations.push('High change frequency - consider refactoring for stability');
|
|
176
|
+
}
|
|
177
|
+
if (file.authors.length > 8) {
|
|
178
|
+
recommendations.push('Many different authors - ensure clear ownership');
|
|
179
|
+
}
|
|
180
|
+
const daysSinceLastChange = Math.floor((Date.now() - file.lastChange.getTime()) / (1000 * 60 * 60 * 24));
|
|
181
|
+
if (daysSinceLastChange > 180) {
|
|
182
|
+
recommendations.push('No recent changes - may be stable or abandoned');
|
|
183
|
+
}
|
|
184
|
+
debtFiles.push({
|
|
185
|
+
file: file.path,
|
|
186
|
+
riskLevel,
|
|
187
|
+
changeCount: file.changeCount,
|
|
188
|
+
authorCount: file.authors.length,
|
|
189
|
+
lastModified: file.lastChange,
|
|
190
|
+
score,
|
|
191
|
+
recommendations
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return debtFiles.sort((a, b) => b.score - a.score).slice(0, 10);
|
|
195
|
+
}
|
|
196
|
+
function analyzeOwnership(files) {
|
|
197
|
+
const ownershipData = [];
|
|
198
|
+
for (const file of files) {
|
|
199
|
+
// Only analyze files with multiple commits
|
|
200
|
+
if (file.changeCount < 3)
|
|
201
|
+
continue;
|
|
202
|
+
// Calculate owner percentages
|
|
203
|
+
const owners = Object.entries(file.authorDistribution)
|
|
204
|
+
.map(([author, commits]) => ({
|
|
205
|
+
author,
|
|
206
|
+
commits,
|
|
207
|
+
percentage: (commits / file.changeCount) * 100
|
|
208
|
+
}))
|
|
209
|
+
.sort((a, b) => b.commits - a.commits)
|
|
210
|
+
.slice(0, 5); // Top 5 contributors
|
|
211
|
+
// Determine ownership type
|
|
212
|
+
let ownershipType = 'collaborative';
|
|
213
|
+
let busFactorRisk = 0;
|
|
214
|
+
if (owners.length === 1 || owners[0].percentage >= 90) {
|
|
215
|
+
ownershipType = 'single-owner';
|
|
216
|
+
busFactorRisk = 9;
|
|
217
|
+
}
|
|
218
|
+
else if (owners[0].percentage >= 70) {
|
|
219
|
+
ownershipType = 'single-owner';
|
|
220
|
+
busFactorRisk = 7;
|
|
221
|
+
}
|
|
222
|
+
else if (owners[0].percentage >= 50) {
|
|
223
|
+
ownershipType = 'shared';
|
|
224
|
+
busFactorRisk = 4;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
ownershipType = 'collaborative';
|
|
228
|
+
busFactorRisk = 2;
|
|
229
|
+
}
|
|
230
|
+
ownershipData.push({
|
|
231
|
+
file: file.path,
|
|
232
|
+
owners,
|
|
233
|
+
ownershipType,
|
|
234
|
+
busFactorRisk
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// Return files with ownership risks
|
|
238
|
+
return ownershipData
|
|
239
|
+
.filter(o => o.busFactorRisk >= 7)
|
|
240
|
+
.sort((a, b) => b.busFactorRisk - a.busFactorRisk)
|
|
241
|
+
.slice(0, 10);
|
|
242
|
+
}
|
|
243
|
+
function getEmptyAnalysis() {
|
|
244
|
+
return {
|
|
245
|
+
topFiles: [],
|
|
246
|
+
topDirectories: [],
|
|
247
|
+
technicalDebt: [],
|
|
248
|
+
ownershipRisks: [],
|
|
249
|
+
totalFilesAnalyzed: 0
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function getRiskLevelColor(level) {
|
|
253
|
+
switch (level) {
|
|
254
|
+
case 'critical': return '🔴';
|
|
255
|
+
case 'high': return '🟠';
|
|
256
|
+
case 'medium': return '🟡';
|
|
257
|
+
case 'low': return '🟢';
|
|
258
|
+
default: return '⚪';
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.getRiskLevelColor = getRiskLevelColor;
|
|
262
|
+
function getOwnershipIcon(type) {
|
|
263
|
+
switch (type) {
|
|
264
|
+
case 'single-owner': return '🔴';
|
|
265
|
+
case 'shared': return '🟡';
|
|
266
|
+
case 'collaborative': return '🟢';
|
|
267
|
+
default: return '⚪';
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.getOwnershipIcon = getOwnershipIcon;
|