-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
executable file
·41 lines (36 loc) · 1.13 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
const child_process = require('child_process');
// Get some data from git
const commitCount = child_process
.execSync('git rev-list --all --count')
.toString()
.trim();
const commitMessages = child_process
.execSync('git log --format=%s')
.toString()
.trim();
// Process commit messages
const countByTypes = commitMessages
.split('\n')
// Convert into an object of tag/count pairs including untagged
.reduce((acc, val) => {
// Find the name of the tag if it exists otherwise mark it as 'untagged'
const tag = val.match(/^[a-zA-Z1-9\-]+:\ .+/) ? val.split(':')[0].trim().toLowerCase() : 'untagged';
if (acc[tag]) {
acc[tag]++;
} else {
acc[tag] = 1;
}
return acc;
}, {});
// Print the stats
console.log('dotfile stats');
console.log('=============\n');
console.log(`Total commits: ${commitCount}`);
console.log('Commits by tag:');
Object.keys(countByTypes)
.sort((a, b) => countByTypes[b] - countByTypes[a])
.forEach((key) => {
const percent = ((countByTypes[key] / commitCount) * 100).toFixed(2);
console.log(` ${key}: ${countByTypes[key]} (${percent}%)`)
});