Commit 5acb8ff4 authored by Tingluo Huang's avatar Tingluo Huang Committed by TingluoHuang
Browse files

make octokit follow proxy setting.

parent db41740e
Loading
Loading
Loading
Loading
+1688 −19

File changed.

Preview size limit exceeded, changes collapsed.

+16 −4
Changes for package-lock.json: 16 added lines, 4 removed lines.
Original line number Diff line number Diff line
{
  "name": "checkout",
  "version": "2.0.0",
  "version": "2.0.1",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
@@ -929,6 +929,11 @@
      "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==",
      "dev": true
    },
    "agent-base": {
      "version": "5.1.1",
      "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz",
      "integrity": "sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g=="
    },
    "ajv": {
      "version": "6.10.2",
      "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz",
@@ -1707,7 +1712,6 @@
      "version": "4.1.1",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
      "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
      "dev": true,
      "requires": {
        "ms": "^2.1.1"
      }
@@ -3670,6 +3674,15 @@
        "sshpk": "^1.7.0"
      }
    },
    "https-proxy-agent": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-4.0.0.tgz",
      "integrity": "sha512-zoDhWrkR3of1l9QAL8/scJZyLu8j/gBkcwcaQOZh7Gyh/+uJQzGVETdgT30akuwkpL8HTRfssqI3BZuV18teDg==",
      "requires": {
        "agent-base": "5",
        "debug": "4"
      }
    },
    "iconv-lite": {
      "version": "0.4.24",
      "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@@ -4985,8 +4998,7 @@
    "ms": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
      "dev": true
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
    },
    "mute-stream": {
      "version": "0.0.7",
+1
Changes for package.json: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
    "@actions/github": "^2.0.0",
    "@actions/io": "^1.0.1",
    "@actions/tool-cache": "^1.1.2",
    "https-proxy-agent": "^4.0.0",
    "uuid": "^3.3.3"
  },
  "devDependencies": {
+37 −1
Changes for src/github-api-helper.ts: 37 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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)}
    })
  }
}