Skip to content

Commit 30bfa27

Browse files
committed
feat: allow including and excluding files with glob patterns
1 parent 37ac12b commit 30bfa27

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

cli.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const program = require('commander');
44
const fs = require('fs-extra');
55
const parse = require('parse-git-numstat');
6+
const multimatch = require('multimatch');
67

78
const { table } = require('table');
89
const { createObjectCsvStringifier } = require('csv-writer');
@@ -13,6 +14,8 @@ const buildBusfactors = require('./lib/build-busfactors');
1314

1415
program.option('-g, --gitlog <gitlog>', 'path to git log with numstat', 'gitlog.txt');
1516
program.option('-t, --threshold <threshold>', 'report busfactor below this threshold', 3);
17+
program.option('-e, --exclude <glob>', 'glob pattern to exclude files', repeatable, []);
18+
program.option('-i, --include <glob>', 'glob pattern to include files', repeatable, []);
1619
program.option('-r, --report <table/csv>', 'report bus factors in csv or console table format', 'table');
1720

1821
program.parse(process.argv);
@@ -32,7 +35,16 @@ async function buildReport(args) {
3235

3336
const commits = markDeleted(normalizeRenames(gitlog.filter(commit => !commit.merge)));
3437

35-
const busfactors = buildBusfactors(commits).filter(file => file.busfactor < args.threshold);
38+
const matchPattern = buildMatchPattern(args.include, args.exclude);
39+
40+
const busfactors = buildBusfactors(commits)
41+
.filter(file => file.busfactor < args.threshold)
42+
.filter(file => multimatch([file.filepath], matchPattern).length == 1);
43+
44+
if (busfactors.length == 0) {
45+
console.log(`No files with bus factor less than threshold ${args.threshold} found`);
46+
return;
47+
}
3648

3749
if (args.report == 'csv') {
3850
const records = busfactors.map(file => ({
@@ -68,4 +80,12 @@ async function buildReport(args) {
6880
}
6981
}
7082

83+
function buildMatchPattern(includes, excludes) {
84+
return [].concat(includes.length > 0 ? includes : '**/*.*', excludes.map(e => `!${e}`));
85+
}
86+
87+
function repeatable(value, previous) {
88+
return [...previous, value];
89+
}
90+
7191
buildReport(program);

package-lock.json

Lines changed: 36 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"name": "gitlog-busfactor",
33
"version": "1.0.0",
44
"description": "Calculates the bus factor from git log",
5-
"bin" : { "gitlog-busfactor" : "./cli.js" },
5+
"bin": {
6+
"gitlog-busfactor": "./cli.js"
7+
},
68
"main": "lib/build-busfactors.js",
79
"scripts": {
810
"start": "nodemon cli.js",
@@ -32,6 +34,7 @@
3234
"commander": "^3.0.1",
3335
"csv-writer": "^1.5.0",
3436
"fs-extra": "^8.1.0",
37+
"multimatch": "^4.0.0",
3538
"parse-git-numstat": "^1.0.2",
3639
"table": "^5.4.6"
3740
},

0 commit comments

Comments
 (0)