From 0373b38e61717f29ed46211dbe5d8403804a813d Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Thu, 16 Jan 2020 12:47:39 -0500 Subject: make octokit follow proxy setting. --- src/github-api-helper.ts | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/github-api-helper.ts') diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index 83a2b86..f9d0766 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -8,6 +8,7 @@ import * as retryHelper from './retry-helper' import * as toolCache from '@actions/tool-cache' import {default as uuid} from 'uuid/v4' import {ReposGetArchiveLinkParams} from '@octokit/rest' +import HttpsProxyAgent from 'https-proxy-agent' const IS_WINDOWS = process.platform === 'win32' @@ -74,7 +75,7 @@ async function downloadArchive( ref: string, commit: string ): Promise { - const octokit = new github.GitHub(authToken) + const octokit = createOctokit(authToken) const params: ReposGetArchiveLinkParams = { owner: owner, repo: repo, @@ -90,3 +91,38 @@ async function downloadArchive( return Buffer.from(response.data) // response.data is ArrayBuffer } + +function createOctokit(authToken: string): github.GitHub { + let proxyVar: string = + process.env['https_proxy'] || process.env['HTTPS_PROXY'] || '' + + if (!proxyVar) { + return new github.GitHub(authToken) + } + + let noProxy: string = process.env['no_proxy'] || process.env['NO_PROXY'] || '' + + let bypass: boolean = false + if (noProxy) { + let bypassList = noProxy.split(',') + for (let i = 0; i < bypassList.length; i++) { + let item = bypassList[i] + if ( + item && + typeof item === 'string' && + item.trim().toLocaleLowerCase() === 'github.com' + ) { + bypass = true + break + } + } + } + + if (bypass) { + return new github.GitHub(authToken) + } else { + return new github.GitHub(authToken, { + request: {agent: new HttpsProxyAgent(proxyVar)} + }) + } +} -- cgit v1.2.3