-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'GuyPaddock-feature/per-branch-filter'
- Loading branch information
Showing
2 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,9 @@ var config = { | |
// Aliases of emails for grouping the same activity as one person | ||
emailAliases: { | ||
"[email protected]": "[email protected]" | ||
} | ||
}, | ||
|
||
branch: null | ||
}; | ||
|
||
function main() { | ||
|
@@ -55,7 +57,7 @@ function main() { | |
} | ||
} | ||
|
||
getCommits(config.gitPath).then(function(commits) { | ||
getCommits(config.gitPath, config.branch).then(function(commits) { | ||
var commitsByEmail = _.groupBy(commits, function(commit) { | ||
var email = commit.author.email || 'unknown' | ||
if (config.emailAliases !== undefined && config.emailAliases[email] !== undefined) { | ||
|
@@ -155,6 +157,11 @@ function parseArgs() { | |
'Git repository to analyze.' + | ||
' Default: ' + config.gitPath, | ||
String | ||
) | ||
.option( | ||
'-b, --branch [branch-name]', | ||
'Analyze only data on the specified branch. Default: ' + config.branch, | ||
String | ||
); | ||
|
||
program.on('--help', function() { | ||
|
@@ -182,6 +189,10 @@ function parseArgs() { | |
console.log(''); | ||
console.log(' $ git hours --since 2015-01-31'); | ||
console.log(''); | ||
console.log(' - Estimate hours work in repository on the "master" branch'); | ||
console.log(''); | ||
console.log(' $ git hours --branch master'); | ||
console.log(''); | ||
console.log(' For more details, visit https://github.com/kimmobrunfeldt/git-hours'); | ||
console.log(''); | ||
}); | ||
|
@@ -237,7 +248,8 @@ function mergeDefaultsWithArgs(conf) { | |
since: program.since || conf.since, | ||
until: program.until || conf.until, | ||
gitPath: program.path || conf.gitPath, | ||
mergeRequest: program.mergeRequest !== undefined ? (program.mergeRequest == "true") : conf.mergeRequest | ||
mergeRequest: program.mergeRequest !== undefined ? (program.mergeRequest == "true") : conf.mergeRequest, | ||
branch: program.branch || conf.branch | ||
}; | ||
} | ||
|
||
|
@@ -273,15 +285,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) { | ||
|