Skip to content

Instantly share code, notes, and snippets.

@supasympa
Created February 19, 2019 23:38
Show Gist options
  • Save supasympa/97af30969a3f0c1777c8a6b0df88fc95 to your computer and use it in GitHub Desktop.
Save supasympa/97af30969a3f0c1777c8a6b0df88fc95 to your computer and use it in GitHub Desktop.
Analyse file changes across a git repo.
const gitlog = require('gitlog');
const {resolve} = require('path');
const changesToFiles = (opts = { repoPath: __dirname }) => {
const commitMap = gitlog({
repo: opts.repoPath
, number: opts.max || 1999999
, execOptions:
{
maxBuffer: 99999 * 1024
}
}).map(c => c.files)
.reduce( (filesArray, files) => ([...filesArray, ...files]), [])
.sort()
.reduce((a, i) =>(( typeof a[i] === 'undefined' ? (a[i] = 1) : (a[i] = a[i] + 1) ) && a ), {});
return Object.keys(commitMap)
.map(k => ([k, commitMap[k]]))
.sort((a, b) => (b[1] - a[1]))
.slice(0, opts.top || 100)
.reduce((a, i) => ((a[i[0]] = i[1]) && a), {});
};
/*
console.log(changesToFiles({
repoPath: resolve(__dirname, '../../react'),
top: 10
})
);
*/
module.exports = changesToFiles;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment