Skip to content

Commit

Permalink
Adds a filter for per-branch statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyPaddock committed Feb 10, 2017
1 parent fb76ed3 commit 77cca39
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var config = {

// Include commits since time x
since: 'always',
until: 'always'
until: 'always',
branch: null
};

function main() {
Expand All @@ -30,7 +31,7 @@ function main() {
config.since = parseSinceDate(config.since);
config.until = parseUntilDate(config.until);

getCommits('.').then(function(commits) {
getCommits('.', config.branch).then(function(commits) {
var commitsByEmail = _.groupBy(commits, function(commit) {
return commit.author.email || 'unknown';
});
Expand Down Expand Up @@ -105,6 +106,11 @@ function parseArgs() {
'Analyze data until certain date.' +
' [always|yesterday|today|lastweek|thisweek|yyyy-mm-dd] Default: ' + config.until,
String
)
.option(
'-b, --branch [branch name]',
'Analyze only data on the specified branch. Default: ' + config.branch,
String
);

program.on('--help', function() {
Expand Down Expand Up @@ -132,6 +138,10 @@ function parseArgs() {
console.log('');
console.log(' $ git hours --since 2015-01-31');
console.log('');
console.log(' - Estimate hours work in repository on the "develop" branch');
console.log('');
console.log(' $ git hours --branch develop');
console.log('');
console.log(' For more details, visit https://github.com/kimmobrunfeldt/git-hours');
console.log('');
});
Expand Down Expand Up @@ -170,7 +180,8 @@ function mergeDefaultsWithArgs(conf) {
maxCommitDiffInMinutes: program.maxCommitDiff || conf.maxCommitDiffInMinutes,
firstCommitAdditionInMinutes: program.firstCommitAdd || conf.firstCommitAdditionInMinutes,
since: program.since || conf.since,
until: program.until || conf.until
until: program.until || conf.until,
branch: program.branch || conf.branch
};
}

Expand Down Expand Up @@ -206,15 +217,23 @@ function estimateHours(dates) {
}

// Promisify nodegit's API of getting all commits in repository
function getCommits(gitPath) {
function getCommits(gitPath, branch) {
return git.Repository.open(gitPath)
.then(function(repo) {
var allReferences = getAllReferences(repo);

return Promise.filter(allReferences, function(reference) {
return reference.match(/refs\/heads\/.*/);
})
.map(function(branchName) {
if (branch) {
filterPromise = Promise.filter(allReferences, function(reference) {
return (reference == ('refs/heads/' + branch));
});
}
else {
filterPromise = Promise.filter(allReferences, function(reference) {
return reference.match(/refs\/heads\/.*/);
});
}

return filterPromise.map(function(branchName) {
return getBranchLatestCommit(repo, branchName);
})
.map(function(branchLatestCommit) {
Expand Down

0 comments on commit 77cca39

Please sign in to comment.