feat: revise proxy implementation

This commit is contained in:
Peter Evans 2022-12-12 15:29:33 +09:00
parent e9de0054f9
commit 39e13ab4bf
8 changed files with 92 additions and 53475 deletions

View file

@ -1,7 +1,8 @@
import {Octokit as Core} from '@octokit/core'
import {paginateRest} from '@octokit/plugin-paginate-rest'
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
import ProxyAgent from 'proxy-agent'
import {HttpsProxyAgent} from 'https-proxy-agent'
import {getProxyForUrl} from 'proxy-from-env'
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
export {OctokitOptions} from '@octokit/core/dist-types/types'
@ -13,16 +14,10 @@ export const Octokit = Core.plugin(
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
function autoProxyAgent(octokit: Core) {
const proxy =
process.env.https_proxy ||
process.env.HTTPS_PROXY ||
process.env.http_proxy ||
process.env.HTTP_PROXY
if (!proxy) return
const agent = new ProxyAgent()
octokit.hook.before('request', options => {
options.request.agent = agent
const proxy = getProxyForUrl(options.url)
if (proxy) {
options.request.agent = new HttpsProxyAgent(proxy)
}
})
}