summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rwxr-xr-xindex.js56
-rw-r--r--test/test-functional.js51
3 files changed, 113 insertions, 3 deletions
diff --git a/README.md b/README.md
index ecc5ad1..a09cefb 100644
--- a/README.md
+++ b/README.md
@@ -101,6 +101,7 @@ Help
-V, --version output the version number
-d, --max-commit-diff [max-commit-diff] maximum difference in minutes between commits counted to one session. Default: 120
-a, --first-commit-add [first-commit-add] how many minutes first commit of session should add to total. Default: 120
+ -s, --since [since-certain-date] Analyze data since certain date. [always|yesterday|tonight|lastweek|yyyy-mm-dd] Default: always'
Examples:
@@ -116,6 +117,14 @@ Help
$ git hours --first-commit-add 300
+ - Estimate hours work in repository since yesterday
+
+ $ git hours --since yesterday
+
+ - Estimate hours work in repository since 2015-01-31
+
+ $ git hours --since 2015-01-31
+
For more details, visit https://github.com/kimmobrunfeldt/git-hours
diff --git a/index.js b/index.js
index 6ea3bb2..066d912 100755
--- a/index.js
+++ b/index.js
@@ -15,12 +15,16 @@ var config = {
maxCommitDiffInMinutes: 2 * 60,
// How many minutes should be added for the first commit of coding session
- firstCommitAdditionInMinutes: 2 * 60
+ firstCommitAdditionInMinutes: 2 * 60,
+
+ //Since data
+ since: 'always'
};
function main() {
parseArgs();
config = mergeDefaultsWithArgs(config);
+ parseSinceDate(config);
commits('.').then(function(commits) {
var commitsByEmail = _.groupBy(commits, function(commit) {
@@ -79,6 +83,11 @@ function parseArgs() {
'-a, --first-commit-add [first-commit-add]',
'how many minutes first commit of session should add to total. Default: ' + config.firstCommitAdditionInMinutes,
int
+ )
+ .option(
+ '-s, --since [since-certain-date]',
+ 'Analyze data since certain date. [always|yesterday|tonight|lastweek|yyyy-mm-dd] Default: ' + config.since,
+ String
);
program.on('--help', function() {
@@ -96,6 +105,14 @@ function parseArgs() {
console.log('');
console.log(' $ git hours --first-commit-add 300');
console.log('');
+ console.log(' - Estimate hours work in repository since yesterday');
+ console.log('');
+ console.log(' $ git hours --since yesterday');
+ console.log('');
+ console.log(' - Estimate hours work in repository since 2015-01-31');
+ console.log('');
+ console.log(' $ git hours --since 2015-01-31');
+ console.log('');
console.log(' For more details, visit https://github.com/kimmobrunfeldt/git-hours');
console.log('');
});
@@ -103,11 +120,42 @@ function parseArgs() {
program.parse(process.argv);
}
+function parseSinceDate(options){
+ var justNow, thisPeriod, paramDate;
+ switch(options.since){
+ case 'tonight':
+ justNow = new Date();
+ thisPeriod = new Date(justNow.getFullYear(), justNow.getMonth(), justNow.getUTCDate());
+ config.since = thisPeriod;
+ break;
+ case 'yesterday':
+ justNow = new Date();
+ thisPeriod = new Date(justNow.getFullYear(), justNow.getMonth(), justNow.getUTCDate()-1);
+ config.since = thisPeriod;
+ break;
+ case 'lastweek':
+ justNow = new Date();
+ thisPeriod = new Date(justNow.getFullYear(), justNow.getMonth(), justNow.getUTCDate()-7);
+ config.since = thisPeriod;
+ break;
+ case 'always':
+ break;
+ default:
+ paramDate = new Date(String(config.since));
+ if(paramDate === undefined){
+ config.since = 'always';
+ }else{
+ config.since = paramDate;
+ }
+ }
+}
+
function mergeDefaultsWithArgs(config) {
return {
range: program.range,
maxCommitDiffInMinutes: program.maxCommitDiff || config.maxCommitDiffInMinutes,
- firstCommitAdditionInMinutes: program.firstCommitAdd || config.firstCommitAdditionInMinutes
+ firstCommitAdditionInMinutes: program.firstCommitAdd || config.firstCommitAdditionInMinutes,
+ since: program.since || config.since
};
}
@@ -227,7 +275,9 @@ function getBranchCommits(branchLatestCommit) {
author: author
};
- commits.push(commitData);
+ if(commitData.date > config.since || config.since === 'always'){
+ commits.push(commitData);
+ }
});
history.on('end', function() {
diff --git a/test/test-functional.js b/test/test-functional.js
index e91f281..d716e07 100644
--- a/test/test-functional.js
+++ b/test/test-functional.js
@@ -2,6 +2,8 @@ var _ = require('lodash');
var assert = require("assert");
var exec = require('child_process').exec;
+var totalHoursCount;
+
describe('git-hours', function() {
describe('cli', function() {
@@ -16,9 +18,58 @@ describe('git-hours', function() {
var work = JSON.parse(stdout);
assert.notEqual(work.total.hours.length, 0);
assert.notEqual(work.total.commits.length, 0);
+ totalHoursCount = work.total.hours;
+ done();
+ });
+ });
+ });
+
+ describe('Since option', function(){
+ it('Should analyse since today', function(done) {
+ exec('node index.js --since today', function(err, stdout, stderr) {
+ assert.ifError(err);
+ var work = JSON.parse(stdout);
+ assert.strictEqual(typeof work.total.hours, 'number');
+ done();
+ });
+ });
+
+ it('Should analyse since yesterday', function(done) {
+ exec('node index.js --since yesterday', function(err, stdout, stderr) {
+ assert.ifError(err);
+ var work = JSON.parse(stdout);
+ assert.strictEqual(typeof work.total.hours, 'number');
+ done();
+ });
+ });
+
+ it('Should analyse since last week', function(done){
+ exec('node index.js --since lastweek', function(err, stdout, stderr) {
+ assert.ifError(err);
+ var work = JSON.parse(stdout);
+ assert.strictEqual(typeof work.total.hours, 'number');
+ done();
+ });
+ });
+
+ it('Should analyse since a specific date', function(done){
+ exec('node index.js --since 2015-01-01', function(err, stdout, stderr) {
+ assert.ifError(err);
+ var work = JSON.parse(stdout);
+ assert.notEqual(work.total.hours, 0);
+ done();
+ });
+ });
+ it('Should analyse as without param', function(done){
+ exec('node index.js --since always', function(err, stdout, stderr) {
+ assert.ifError(err);
+ var work = JSON.parse(stdout);
+ assert.equal(work.total.hours, totalHoursCount);
done();
});
});
});
+
+
});