Skip to content

Commit c3b3bc6

Browse files
committed
Remove check_token parameter. Rework dump mechanic to write the dump every time it's updated.
1 parent c40c849 commit c3b3bc6

File tree

6 files changed

+46
-33
lines changed

6 files changed

+46
-33
lines changed

src/gtt-report.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ program
5757
.option('--user_columns', 'include user columns in the report')
5858
.option('--quiet', 'only output report')
5959
.option('--verbose', 'show verbose output')
60-
.option('--check_token', 'check the access token')
6160
.option('--show_without_times', 'show issues/merge requests without time records')
6261
.option('-p --proxy <proxy>', 'use a proxy server with the given url')
6362
.option('--from_dump <file>', 'instead of querying gitlab, use data from the given dump file')
@@ -78,6 +77,13 @@ if (program.from_dump && fs.existsSync(program.from_dump)) {
7877
if (data._dump) config.dump = data._dump;
7978
}
8079

80+
// if writing a dump, set config accordingly
81+
if (program.output === "dump") {
82+
config.on("dump-updated", () => {
83+
new Output['dump'](config);
84+
});
85+
}
86+
8187
// overwrite config with args and opts
8288
config
8389
.set('project', cli.project())
@@ -110,22 +116,21 @@ config
110116
.set('type', program.type)
111117
.set('subgroups', program.subgroups)
112118
.set('_verbose', program.verbose)
113-
.set('_checkToken', program.check_token)
114119
.set('_createDump', program.output === 'dump');
115120

116121
// date shortcuts
117-
if(program.today)
122+
if (program.today)
118123
config
119124
.set('from', moment().startOf('day'))
120125
.set('to', moment().endOf('day'));
121-
if(program.this_week)
126+
if (program.this_week)
122127
config
123128
.set('from', moment().startOf('week'))
124129
.set('to', moment().endOf('week'));
125-
if(program.this_month)
130+
if (program.this_month)
126131
config
127132
.set('from', moment().startOf('month'))
128-
.set('to', moment().endOf('month'));
133+
.set('to', moment().endOf('month'));
129134

130135
Cli.quiet = config.get('quiet');
131136
Cli.verbose = config.get('_verbose');
@@ -193,7 +198,7 @@ new Promise(resolve => {
193198
reports.push(report);
194199
report.getProject()
195200
.then(() => done())
196-
.catch(e => Cli.x(`Project not found or no access rights "${projectLabels}". Run again with --check_token to see if your access token is invalid!`, e));
201+
.catch(e => Cli.x(`Project not found or no access rights "${projectLabels}".`, e));
197202
break;
198203

199204
case 'group':
@@ -222,7 +227,6 @@ new Promise(resolve => {
222227
// get members and user columns
223228
.then(() => new Promise(resolve => {
224229
if (!config.get('userColumns')) return resolve();
225-
226230
reports
227231
.forEach((report, done) => {
228232
report.project.members()

src/gtt-sync.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ const Owner = require('./models/owner');
99
program
1010
.option('-p --proxy <proxy>', 'use a proxy server with the given url')
1111
.option('--verbose', 'show verbose output')
12-
.option('--check_token', 'check the access token')
1312
.parse(process.argv);
1413

1514
Cli.verbose = program.verbose;
1615

1716
let config = new Config(process.cwd())
18-
.set('proxy', program.proxy)
19-
.set('_checkToken', program.check_token),
17+
.set('proxy', program.proxy);
2018
tasks = new Tasks(config),
2119
owner = new Owner(config);
2220

src/include/config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const moment = require('moment');
22
const _ = require('underscore');
33

44
const Time = require('./../models/time');
5+
const EventEmitter = require('events');
56

67
const dates = ['from', 'to'];
78
const objectsWithDefaults = ['timeFormat', 'columns'];
@@ -47,11 +48,13 @@ const defaults = {
4748
/**
4849
* basic config
4950
*/
50-
class config {
51+
class config extends EventEmitter {
5152
/**
5253
* construct
5354
*/
5455
constructor() {
56+
super();
57+
5558
this.data = _.extend({}, defaults);
5659
}
5760

src/include/file-config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class fileConfig extends config {
2020
this.assertGlobalConfig();
2121
this.workDir = workDir;
2222
this.data = Object.assign(this.data, this.localExists() ? this.parseLocal() : this.parseGlobal());
23+
this._dump = {};
2324
this.cache = {
2425
get: this._cacheGet,
2526
set: this._cacheSet,
@@ -132,6 +133,15 @@ class fileConfig extends config {
132133
get local() {
133134
return Fs.join(this.workDir, this.localConfigFile);
134135
}
136+
137+
setDump(key, value) {
138+
this._dump[key] = value;
139+
this.emit('dump-updated');
140+
}
141+
142+
getDump(key) {
143+
return this._dump[key];
144+
}
135145
}
136146

137147
module.exports = fileConfig;

src/models/base.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ class base {
147147
* @param key
148148
*/
149149
setDump(response, key) {
150-
if (!this.config._dump) this.config._dump = {};
151-
152-
this.config._dump[key] = {
150+
this.config.setDump(key, {
153151
headers: response.headers,
154152
body: response.body
155-
};
153+
});
156154
}
157155

158156
/**
@@ -161,7 +159,7 @@ class base {
161159
* @returns {Promise}
162160
*/
163161
getDump(key) {
164-
return new Promise(r => r(this.config.dump[key]));
162+
return new Promise(r => r(this.config.getDump(key)));
165163
}
166164

167165
/**

src/output/dump.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
const Base = require('./base');
2-
const Report = require('../models/report');
1+
const fs = require('fs');
2+
const Config = require('../include/config');
33

4-
class dump extends Base {
4+
class dump {
55
constructor(config, report) {
6-
super(config, report);
6+
let configCopy = new Config();
7+
configCopy.data = Object.assign({}, config.data);
8+
configCopy._dump = config._dump;
79

8-
config.set('url', null, true);
9-
config.set('token', null, true);
10-
config.set('_createDump', false);
11-
config.workDir = null;
12-
config.cache = null;
10+
configCopy.set('url', null, true);
11+
configCopy.set('token', null, true);
12+
configCopy.set('_createDump', false);
13+
configCopy.workDir = null;
14+
configCopy.cache = null;
1315

14-
this.write(JSON.stringify(config));
16+
fs.writeFileSync(configCopy.get('file'), JSON.stringify(configCopy));
1517
}
1618

17-
makeStats() {
19+
make() {
1820
}
1921

20-
makeIssues() {
22+
toStdOut() {
2123
}
2224

23-
makeMergeRequests() {
24-
}
25-
26-
makeRecords() {
25+
toFile(file, resolve) {
26+
if (resolve) resolve();
2727
}
2828
}
2929

0 commit comments

Comments
 (0)