Skip to content

Commit cd471fc

Browse files
committed
Rework base with request instead of got. Add proxy support
1 parent 004d54b commit cd471fc

File tree

8 files changed

+130
-77
lines changed

8 files changed

+130
-77
lines changed

gtt-report.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ program
4848
.option('--user_columns', 'include user columns in the report')
4949
.option('--quiet', 'only output report')
5050
.option('--show_without_times', 'show issues/merge requests without time records')
51+
.option('-p --proxy <proxy>', 'use a proxy server with the given url')
5152
.parse(process.argv);
5253

5354
// init helpers
@@ -80,7 +81,8 @@ config
8081
.set('noWarnings', program.no_warnings)
8182
.set('quiet', program.quiet)
8283
.set('showWithoutTimes', program.show_without_times)
83-
.set('userColumns', program.user_columns);
84+
.set('userColumns', program.user_columns)
85+
.set('proxy', program.proxy);
8486

8587
Cli.quiet = config.get('quiet');
8688

gtt-sync.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ const MergeRequest = require('./models/mergeRequest');
88
const Config = require('./include/file-config');
99
const Cli = require('./include/cli');
1010

11-
program.parse(process.argv);
11+
program
12+
.option('-p --proxy <proxy>', 'use a proxy server with the given url')
13+
.parse(process.argv);
1214

1315
let config = new Config(process.cwd());
1416
let frames = new FrameCollection(config);
1517

18+
config.set('proxy', program.proxy);
19+
1620
let classes = {
1721
issue: Issue,
1822
merge_request: MergeRequest
@@ -43,7 +47,7 @@ frames.filter(frame => {
4347
return !(Math.ceil(frame.duration) === _.reduce(frame.notes, (n, m) => (n + m.time), 0));
4448
});
4549

46-
if(frames.length === 0) process.exit(0);
50+
if (frames.length === 0) process.exit(0);
4751

4852
Cli.bar(`${Cli.process} Syncing time records...`, frames.length);
4953

include/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const dates = ['from', 'to'];
66
const defaults = {
77
url: 'https://gitlab.com/api/v4',
88
token: false,
9+
proxy: false,
910
project: false,
1011
from: "1970-01-01",
1112
to: moment().format(),

models/base.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const got = require('got');
1+
const request = require('request-promise-native');
2+
const url = require('url');
23
const async = require('async');
3-
const querystring = require('querystring');
44

55
/**
66
* base model
@@ -18,6 +18,7 @@ class base {
1818

1919
this._perPage = this.config ? this.config.get('_perPage') : 100;
2020
this._parallel = this.config ? this.config.get('_parallel') : 4;
21+
this._proxy = this.config && this.config.get('proxy') ? this.config.get('proxy') : undefined;
2122
}
2223

2324
/**
@@ -29,10 +30,11 @@ class base {
2930
post(path, data) {
3031
data.private_token = this.token;
3132

32-
return got(`${this.url}${path}`, {
33-
query: querystring.stringify(data),
34-
method: 'POST',
33+
return request.post(`${this.url}${path}`, {
3534
json: true,
35+
body: data,
36+
proxy: this._proxy,
37+
resolveWithFullResponse: true,
3638
headers: {
3739
'PRIVATE-TOKEN': this.token
3840
}
@@ -50,8 +52,10 @@ class base {
5052
path += (path.includes('?') ? '&' : '?') + `private_token=${this.token}`;
5153
path += `&page=${page}&per_page=${perPage}`;
5254

53-
return got(`${this.url}${path}`, {
55+
return request(`${this.url}${path}`, {
5456
json: true,
57+
proxy: this._proxy,
58+
resolveWithFullResponse: true,
5559
headers: {
5660
'PRIVATE-TOKEN': this.token
5761
}

models/project.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class project extends Base {
1414
this.data = data;
1515
}
1616

17+
/**
18+
* make
19+
* @param name
20+
*/
1721
make(name) {
1822
let promise = this.get(`projects/${encodeURIComponent(name)}`);
1923
promise.then(project => this.data = project.body);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"commander": "^2.9.0",
1919
"csv-string": "^2.3.2",
2020
"find-in-files": "^0.4.0",
21-
"got": "^6.7.1",
2221
"hashids": "^1.1.1",
2322
"markdown-pdf": "^8.0.0",
2423
"markdown-table": "^1.1.0",
@@ -28,6 +27,8 @@
2827
"progress": "^2.0.0",
2928
"prompt": "^1.0.0",
3029
"read-yaml": "^1.1.0",
30+
"request": "^2.81.0",
31+
"request-promise-native": "^1.0.4",
3132
"underscore": "^1.8.3"
3233
}
3334
}

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ gtt report --exclude_labels=bug --exclude_labels=feature
200200
# include issues and merge requests in the report hat have no time records
201201
gtt report --show_without_times
202202
203+
# use a proxy server
204+
gtt report --proxy="http://localhost:8080"
205+
203206
# choose a different output than a stdout table
204207
gtt report --output=markdown --file=filename.md
205208
gtt report --output=csv --file=filename.csv
@@ -217,6 +220,9 @@ url: http://gitlab.com/api/v4/
217220
# your api token
218221
token: abcdefghijklmnopqrst
219222
223+
# use a proxy server (defaults to false)
224+
proxy: http://localhost:8080
225+
220226
# default project
221227
project: namespace/projectname
222228

0 commit comments

Comments
 (0)