2020-07-16 10:57:13 +02:00
|
|
|
import {Octokit as Core} from '@octokit/core'
|
|
|
|
import {paginateRest} from '@octokit/plugin-paginate-rest'
|
|
|
|
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
|
2023-04-05 01:41:18 +02:00
|
|
|
import {getProxyForUrl} from 'proxy-from-env'
|
2024-04-25 10:09:16 +02:00
|
|
|
import {ProxyAgent, fetch as undiciFetch} from 'undici'
|
2020-07-16 10:57:13 +02:00
|
|
|
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
|
|
|
|
export {OctokitOptions} from '@octokit/core/dist-types/types'
|
|
|
|
|
2021-05-22 02:32:10 +02:00
|
|
|
export const Octokit = Core.plugin(
|
|
|
|
paginateRest,
|
|
|
|
restEndpointMethods,
|
|
|
|
autoProxyAgent
|
|
|
|
)
|
|
|
|
|
2024-04-25 10:09:16 +02:00
|
|
|
const proxyFetch =
|
|
|
|
(proxyUrl: string): typeof undiciFetch =>
|
|
|
|
(url, opts) => {
|
|
|
|
return undiciFetch(url, {
|
|
|
|
...opts,
|
|
|
|
dispatcher: new ProxyAgent({
|
|
|
|
uri: proxyUrl
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-18 05:14:51 +02:00
|
|
|
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
|
2021-05-22 02:32:10 +02:00
|
|
|
function autoProxyAgent(octokit: Core) {
|
|
|
|
octokit.hook.before('request', options => {
|
2023-04-05 01:41:18 +02:00
|
|
|
const proxy = getProxyForUrl(options.baseUrl)
|
|
|
|
if (proxy) {
|
2024-04-25 10:09:16 +02:00
|
|
|
options.request.fetch = proxyFetch(proxy)
|
2023-04-05 01:41:18 +02:00
|
|
|
}
|
2021-05-22 02:32:10 +02:00
|
|
|
})
|
|
|
|
}
|