diff --git a/index.js b/index.js index ca2f6dc6..2cd53e23 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,20 @@ const Glob = require('./lib/glob') const ConfigManager = require('./lib/configManager') const NopCommand = require('./lib/nopcommand') const env = require('./lib/env') +const { getProxyForUrl } = require('proxy-from-env') +const { setGlobalDispatcher, ProxyAgent } = require('undici') let deploymentConfig module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => { let appSlug = 'safe-settings' + + const baseUrl = env.GHE_HOST ? `${env.GHE_PROTOCOL || 'https'}://${env.GHE_HOST}` : 'https://api.github.com' + const proxyAddress = getProxyForUrl(baseUrl) + if (proxyAddress) { + setGlobalDispatcher(new ProxyAgent(proxyAddress)) + } + async function syncAllSettings (nop, context, repo = context.repo(), ref) { try { deploymentConfig = await loadYamlFileSystem() diff --git a/lib/env.js b/lib/env.js index 94c0ea74..8ed5d927 100644 --- a/lib/env.js +++ b/lib/env.js @@ -6,5 +6,7 @@ module.exports = { CREATE_PR_COMMENT: process.env.CREATE_PR_COMMENT || 'true', CREATE_ERROR_ISSUE: process.env.CREATE_ERROR_ISSUE || 'true', BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false', - FULL_SYNC_NOP: process.env.FULL_SYNC_NOP === 'true' + FULL_SYNC_NOP: process.env.FULL_SYNC_NOP === 'true', + GHE_HOST: process.env.GHE_HOST, + GHE_PROTOCOL: process.env.GHE_PROTOCOL, }