fix: update proxy support to follow octokit change to fetch api (#2867)

This commit is contained in:
Peter Evans 2024-04-25 17:09:16 +09:00 committed by GitHub
parent 9153d834b6
commit 6d6857d369
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25512 additions and 1700 deletions

View file

@ -1,8 +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 {HttpsProxyAgent} from 'https-proxy-agent'
import {getProxyForUrl} from 'proxy-from-env'
import {ProxyAgent, fetch as undiciFetch} from 'undici'
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
export {OctokitOptions} from '@octokit/core/dist-types/types'
@ -12,12 +12,23 @@ export const Octokit = Core.plugin(
autoProxyAgent
)
const proxyFetch =
(proxyUrl: string): typeof undiciFetch =>
(url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: new ProxyAgent({
uri: proxyUrl
})
})
}
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
function autoProxyAgent(octokit: Core) {
octokit.hook.before('request', options => {
const proxy = getProxyForUrl(options.baseUrl)
if (proxy) {
options.request.agent = new HttpsProxyAgent(proxy)
options.request.fetch = proxyFetch(proxy)
}
})
}