From ed56c9c9377a93492b0da570e2d6b11a71094b3e Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Thu, 29 Apr 2021 14:39:33 +0300 Subject: [PATCH] Make sure, that proxy-related environment variables are passed to git process Signed-off-by: Vitaliy Gulyy --- plugins/workspace-plugin/src/exec.ts | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/workspace-plugin/src/exec.ts b/plugins/workspace-plugin/src/exec.ts index 1ccb784e6..a4d6cc497 100644 --- a/plugins/workspace-plugin/src/exec.ts +++ b/plugins/workspace-plugin/src/exec.ts @@ -24,7 +24,7 @@ export async function execute( options.env = mergeProcessEnv(options.env); } - const command = spawn(commandLine, args, options); + const command = spawn(commandLine, args, withProxySettings(options)); let result = ''; let error = ''; @@ -90,3 +90,31 @@ function mergeProcessEnv(env: NodeJS.ProcessEnv | undefined): NodeJS.ProcessEnv return env; } + +function withProxySettings(options?: SpawnOptionsWithoutStdio): SpawnOptionsWithoutStdio { + const HTTP_PROXY = 'http_proxy'; + const HTTPS_PROXY = 'https_proxy'; + const NO_PROXY = 'no_proxy'; + + if (!options) { + options = {}; + } + + if (!options.env) { + options.env = {}; + } + + if (process.env[HTTP_PROXY]) { + options.env.HTTP_PROXY = process.env[HTTP_PROXY]; + } + + if (process.env[HTTPS_PROXY]) { + options.env.HTTPS_PROXY = process.env[HTTPS_PROXY]; + } + + if (process.env[NO_PROXY]) { + options.env.NO_PROXY = process.env[NO_PROXY]; + } + + return options; +}