summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorKimmo Brunfeldt <kimmobrunfeldt@gmail.com>2015-07-24 12:38:41 +0300
committerKimmo Brunfeldt <kimmobrunfeldt@gmail.com>2015-07-24 12:38:41 +0300
commit8aaeee237cb9d9028e7a2592a25ad8468b1f45e4 (patch)
tree70f14f0b28814d2f5931754ba8451e293777cbee /index.js
parentd4a95d8430b9da20b900162d657775855b24fec0 (diff)
downloadgit-hours-8aaeee237cb9d9028e7a2592a25ad8468b1f45e4.zip
git-hours-8aaeee237cb9d9028e7a2592a25ad8468b1f45e4.tar.gz
git-hours-8aaeee237cb9d9028e7a2592a25ad8468b1f45e4.tar.bz2
Sort output based on working hours
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/index.js b/index.js
index d38f616..6ea3bb2 100755
--- a/index.js
+++ b/index.js
@@ -23,28 +23,36 @@ function main() {
config = mergeDefaultsWithArgs(config);
commits('.').then(function(commits) {
- var work = {};
-
var commitsByEmail = _.groupBy(commits, function(commit) {
return commit.author.email || 'unknown';
});
- _.each(commitsByEmail, function(authorCommits, authorEmail) {
- work[authorEmail] = {
+ var authorWorks = _.map(commitsByEmail, function(authorCommits, authorEmail) {
+ return {
+ email: authorEmail,
name: authorCommits[0].author.name,
hours: estimateHours(_.pluck(authorCommits, 'date')),
commits: authorCommits.length
};
});
- var totalHours = _.reduce(work, function(sum, authorWork) {
+ // XXX: This relies on the implementation detail that json is printed
+ // in the same order as the keys were added. This is anyway just for
+ // making the output easier to read, so it doesn't matter if it
+ // isn't sorted in some cases.
+ var sortedWork = {};
+ _.each(_.sortBy(authorWorks, 'hours'), function(authorWork) {
+ sortedWork[authorWork.email] = _.omit(authorWork, 'email');
+ });
+
+ var totalHours = _.reduce(sortedWork, function(sum, authorWork) {
return sum + authorWork.hours;
}, 0);
- work.total = {
+ sortedWork.total = {
hours: totalHours,
commits: commits.length
};
- console.log(JSON.stringify(work, undefined, 2));
+ console.log(JSON.stringify(sortedWork, undefined, 2));
}).catch(function(e) {
console.error(e.stack);
});