Skip to content

Commit 941c78a

Browse files
committed
Add check for valid time-formats. Add option to show issues without time records
1 parent 209e43e commit 941c78a

File tree

8 files changed

+21
-5
lines changed

8 files changed

+21
-5
lines changed

gtt-log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ _.each(frames, (frames, date) => {
3636
frames
3737
.sort((a, b) => moment(a.start).isBefore(moment(b.start)) ? -1 : 1)
3838
.forEach(frame => {
39-
console.log(` ${frame.id} ${moment(frame.start).format('HH:mm').green} to ${moment(frame.stop).format('hh:mm').green}\t${toHumanReadable(frame.duration)}\t${frame.project.magenta}\t${(frame.resource.type + ' #' + frame.resource.id).blue}`)
39+
console.log(` ${frame.id} ${moment(frame.start).format('HH:mm').green} to ${moment(frame.stop).format('HH:mm').green}\t${toHumanReadable(frame.duration)}\t${frame.project.magenta}\t${(frame.resource.type + ' #' + frame.resource.id).blue}`)
4040
});
4141
});

gtt-report.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('underscore');
22
const fs = require('fs');
33
const program = require('commander');
4+
const moment = require('moment');
45

56
const Cli = require('./include/cli');
67
const Config = require('./include/file-config');
@@ -44,6 +45,7 @@ program
4445
.option('--merge_request_columns <columns>', 'include the given columns in the merge request part of the report', collect, null)
4546
.option('--user_columns', 'include user columns in the report')
4647
.option('--quiet', 'only output report')
48+
.option('--show_without_times', 'show issues/merge requests without time records')
4749
.parse(process.argv);
4850

4951
// init helpers
@@ -75,6 +77,7 @@ config
7577
.set('noHeadlines', program.no_headlines)
7678
.set('noWarnings', program.no_warnings)
7779
.set('quiet', program.quiet)
80+
.set('showWithoutTimes', program.show_without_times)
7881
.set('userColumns', program.user_columns);
7982

8083
Cli.quiet = config.get('quiet');
@@ -92,6 +95,12 @@ if ((config.get('report').includes('merge_requests') && !config.get('query').inc
9295
if (!Output[config.get('output')]) {
9396
Cli.error(`The output ${config.get('output')} doesn't exist`);
9497
}
98+
if (!config.get('from').isValid()) {
99+
Cli.error(`FROM is not in a valid ISO date format.`);
100+
}
101+
if (!config.get('to').isValid()) {
102+
Cli.error(`TO is not a in valid ISO date format.`);
103+
}
95104

96105
// create report
97106
let report = new Report(config), output;

gtt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
const version = '1.1.4';
3+
const version = '1.1.5';
44
const program = require('commander');
55

66
program

include/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const defaults = {
2929
noHeadlines: false,
3030
noWarnings: false,
3131
quiet: false,
32+
showWithoutTimes: true,
3233
_perPage: 100,
3334
_parallel: 10
3435
};

models/hasTimes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class hasTimes extends Base {
6969
// only include times by the configured user
7070
(this.config.get('user') && this.config.get('user') !== note.author.username) ||
7171
// filter out times that are not in the given time frame
72-
!(created.isSameOrAfter(this.config.get('from')) && created.isSameOrBefore(this.config.get('to'))) ||
72+
!(created.isSameOrAfter(moment(this.config.get('from'))) && created.isSameOrBefore(moment(this.config.get('to')))) ||
7373
// filter out notes that are no time things
7474
!(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !(removeMatch = removeRegex.exec(note.body))
7575
) return done();

models/report.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class report extends Base {
8686
* @returns {Array}
8787
*/
8888
static filter(issues) {
89-
return issues.filter(issue => issue.times && issue.times.length > 0);
89+
return issues.filter(issue => (this.config.get('showWithoutTimes') || issue.times && issue.times.length > 0));
9090
}
9191

9292
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitlab-time-tracker",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "A CLI that makes working with GitLabs time tracking feature more enjoyable",
55
"main": "gtt.js",
66
"scripts": {},

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ gtt report --include_labels=pending --include_labels=approved
169169
# exclude the given labels from the results
170170
gtt report --exclude_labels=bug --exclude_labels=feature
171171
172+
# include issues and merge requests in the report hat have no time records
173+
gtt report --show_without_times
174+
172175
# choose a different output than a stdout table (json coming soon)
173176
gtt report --output=markdown --file=filename.md
174177
gtt report --output=csv --file=filename.csv
@@ -292,6 +295,9 @@ noHeadlines: true
292295
# hide warnings in report
293296
noWarnings: true
294297
298+
# include issues and merge requests in the report hat have no time records
299+
showWithoutTimes: true
300+
295301
# change number of concurrent connections.
296302
# handle with care, we don't want to spam GitLabs API too much
297303
_parallel: 4

0 commit comments

Comments
 (0)