Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const ProxyAgent = require('proxy-agent');
const { globalAgent } = require('https');
const { spawnSync } = require('child_process');
const { getMergedConfig } = require('./config');

function proxy() {
let proxyUrl = getMergedConfig().proxy;
if (proxyUrl == null || proxyUrl === '') {
proxyUrl = spawnSync(
'git',
['config', '--get', '--path', 'https.proxy']
).stdout.toString();
}
if (proxyUrl == null || proxyUrl === '') {
return globalAgent;
} else {
return new ProxyAgent(proxyUrl);
}
}

module.exports = proxy;
5 changes: 5 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const fetch = require('node-fetch');
const fs = require('fs');
const path = require('path');
const { CI_DOMAIN } = require('./ci/ci_type_parser');
const proxy = require('./proxy');

class Request {
constructor(credentials) {
this.credentials = credentials;
this.proxyAgent = proxy();
}

loadQuery(file) {
Expand All @@ -16,6 +18,7 @@ class Request {
}

async text(url, options = {}) {
options.agent = this.proxyAgent;
if (url.startsWith(`https://${CI_DOMAIN}`)) {
options.headers = options.headers || {};
Object.assign(options.headers, this.getJenkinsHeaders());
Expand All @@ -24,6 +27,7 @@ class Request {
}

async json(url, options = {}) {
options.agent = this.proxyAgent;
options.headers = options.headers || {};
options.headers.Accept = 'application/json';
if (url.startsWith(`https://${CI_DOMAIN}`)) {
Expand Down Expand Up @@ -65,6 +69,7 @@ class Request {
}
const url = 'https://api.github.com/graphql';
const options = {
agent: this.proxyAgent,
method: 'POST',
headers: {
Authorization: `Basic ${githubCredentials}`,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"lodash": "^4.17.15",
"node-fetch": "^2.6.0",
"ora": "^4.0.4",
"proxy-agent": "^3.1.1",
"replace-in-file": "^6.0.0",
"rimraf": "^3.0.2",
"yargs": "^15.3.1"
Expand Down