forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtt-log.js
More file actions
executable file
·41 lines (34 loc) · 1.66 KB
/
gtt-log.js
File metadata and controls
executable file
·41 lines (34 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const _ = require('underscore');
const program = require('commander');
const colors = require('colors');
const moment = require('moment');
const Config = require('./include/file-config');
const Cli = require('./include/cli');
const Time = require('./models/time');
const Tasks = require('./include/tasks');
program
.option('--verbose', 'show verbose output')
.option('--hours_per_day <hours>', 'hours per day for human readable time formats')
.parse(process.argv);
Cli.verbose = program.verbose;
let config = new Config(__dirname)
.set('hoursPerDay', program.hours_per_day),
tasks = new Tasks(config);
function toHumanReadable(input) {
return Time.toHumanReadable(Math.ceil(input), config.get('hoursPerDay'), config.get('timeFormat'));
}
tasks.log()
.then(({frames, times}) => {
Object.keys(frames).sort().forEach(date => {
if (!frames.hasOwnProperty(date)) return;
console.log(`${moment(date).format('MMMM Do YYYY')} (${toHumanReadable(times[date])})`.green);
frames[date]
.sort((a, b) => moment(a.start).isBefore(moment(b.start)) ? -1 : 1)
.forEach(frame => {
let issue = frame.resource.new ? `new ${frame.resource.type + ' "' + frame.resource.id.blue}"` : `${(frame.resource.type + ' #' + frame.resource.id).blue}`;
console.log(` ${frame.id} ${moment(frame.start).format('HH:mm').green} to ${moment(frame.stop).format('HH:mm').green}\t${toHumanReadable(frame.duration)}\t\t${frame.project.magenta}\t\t${issue}`)
});
});
}
)
.catch(error => Cli.error(error));