33const program = require ( 'commander' ) ;
44const fs = require ( 'fs-extra' ) ;
55const parse = require ( 'parse-git-numstat' ) ;
6+ const multimatch = require ( 'multimatch' ) ;
67
78const { table } = require ( 'table' ) ;
89const { createObjectCsvStringifier } = require ( 'csv-writer' ) ;
@@ -13,6 +14,8 @@ const buildBusfactors = require('./lib/build-busfactors');
1314
1415program . option ( '-g, --gitlog <gitlog>' , 'path to git log with numstat' , 'gitlog.txt' ) ;
1516program . 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 , [ ] ) ;
1619program . option ( '-r, --report <table/csv>' , 'report bus factors in csv or console table format' , 'table' ) ;
1720
1821program . 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+
7191buildReport ( program ) ;
0 commit comments