Created
July 14, 2018 23:29
-
-
Save ailtonbsj/8610bcdd104e5e6dc440ab871bbbc20c to your computer and use it in GitHub Desktop.
Get total of hours spend in a git repository
This file contains hidden or 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
#!/usr/bin/env node | |
var exec = require('child_process').exec | |
var child; | |
var initialHoursBeforeCommit = 0.5 | |
if(process.argv[2] == '--help'){ | |
console.log(`Usage: time-gitlog [option] | |
--initial hour Hours before commit. Default 0.5h. | |
--help Get help information | |
NOTE: JUST FOR PERSONAL REPOSITORY. | |
DON'T WORK WITH MORE THAN A USER PER REPOSITORY`) | |
process.exit() | |
} | |
if(process.argv[2] == '--initial') | |
initialHoursBeforeCommit = parseFloat(process.argv[3]) | |
child = exec('git log --pretty=format:"%ct"', function(error, stdout, stderr){ | |
if(error !== null){ | |
console.log('ERROR: '+ error) | |
process.exit() | |
} | |
var times = stdout.split('\n') | |
var hourSession = 0 | |
var totalHour = 0 | |
for(var i = 0; i < (times.length-1); i++){ | |
var diff = times[i] - times[i+1] | |
var hourSpend = diff / (3600) | |
if(hourSpend > 2){ | |
totalHour += hourSession | |
hourSession = initialHoursBeforeCommit | |
} | |
else hourSession += hourSpend | |
} | |
if(hourSession > initialHoursBeforeCommit) | |
totalHour += hourSession | |
console.log('You spend ' + totalHour.toFixed(2) + 'h with this repository!') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment