forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
executable file
·99 lines (88 loc) · 2.47 KB
/
config.js
File metadata and controls
executable file
·99 lines (88 loc) · 2.47 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const moment = require('moment');
const _ = require('underscore');
const Time = require('./../models/time');
const dates = ['from', 'to'];
const objectsWithDefaults = ['timeFormat', 'columns'];
const defaults = {
type: 'project',
subgroups: false,
url: 'https://gitlab.com/api/v4',
token: false,
proxy: false,
project: false,
from: "1970-01-01",
to: moment().format(),
iids: false,
closed: false,
milestone: false,
hoursPerDay: 8,
issueColumns: ['iid', 'title', 'spent', 'total_estimate'],
mergeRequestColumns: ['iid', 'title', 'spent', 'total_estimate'],
recordColumns: ['user', 'date', 'type', 'iid', 'time'],
userColumns: false,
dateFormat: 'DD.MM.YYYY HH:mm:ss',
timeFormat: Time.defaultTimeFormat,
output: 'table',
excludeByLabels: false,
includeByLabels: false,
includeLabels: false,
excludeLabels: false,
query: ['issues', 'merge_requests'],
report: ['stats', 'issues', 'merge_requests', 'records'],
noHeadlines: false,
noWarnings: false,
quiet: false,
showWithoutTimes: false,
_perPage: 100,
_parallel: 10,
_verbose: false,
_checkToken: false
};
/**
* basic config
*/
class config {
/**
* construct
*/
constructor() {
this.data = _.extend({}, defaults);
}
/**
* set a value by the given key.
* it won't get set if the value is null or undefined. you can force
* setting the value by passing true as third parameter.
* @param key
* @param value
* @param force
* @returns {config}
*/
set(key, value, force = false) {
if (!force && (value === null || value === undefined)) return this;
this.data[key] = value;
return this;
}
/**
* get a value by the given key
* @param key
* @param subKey
* @returns {*}
*/
get(key, subKey = false) {
if (dates.includes(key))
return moment(this.data[key]);
if (objectsWithDefaults.includes(key) && _.isObject(this.data[key]))
return subKey && this.data[key][subKey] ? this.data[key][subKey] : defaults[key];
return this.data[key];
}
/**
* get a human readable version of the given time
* @param input
* @param timeFormat
* @returns {string}
*/
toHumanReadable(input, timeFormat = false) {
return Time.toHumanReadable(input, this.get('hoursPerDay'), this.get('timeFormat', timeFormat));
}
}
module.exports = config;