Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTingluo Huang <tihuang@microsoft.com>2020-01-16 12:47:39 -0500
committerTingluoHuang <TingluoHuang@github.com>2020-01-16 14:36:33 -0500
commit0373b38e61717f29ed46211dbe5d8403804a813d (patch)
tree0d878a6fc0c446c6d6f4d4b7bc13a1670dd62b27 /src
parent7ca3468192f1fa956e1fcc853baedb79587fe236 (diff)
make octokit follow proxy setting.users/tihuang/proxysupport
Diffstat (limited to 'src')
-rw-r--r--src/github-api-helper.ts38
1 files changed, 37 insertions, 1 deletions
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<Buffer> {
- 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)}
+ })
+ }
+}