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'
|
2022-10-18 05:14:51 +02:00
|
|
|
import ProxyAgent from 'proxy-agent'
|
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
|
|
|
|
)
|
|
|
|
|
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) {
|
2022-10-18 05:14:51 +02:00
|
|
|
const proxy =
|
|
|
|
process.env.https_proxy ||
|
|
|
|
process.env.HTTPS_PROXY ||
|
|
|
|
process.env.http_proxy ||
|
|
|
|
process.env.HTTP_PROXY
|
2022-08-17 05:25:36 +02:00
|
|
|
|
2021-05-22 02:32:10 +02:00
|
|
|
if (!proxy) return
|
|
|
|
|
2022-10-18 05:14:51 +02:00
|
|
|
const agent = new ProxyAgent()
|
2021-05-22 02:32:10 +02:00
|
|
|
octokit.hook.before('request', options => {
|
|
|
|
options.request.agent = agent
|
|
|
|
})
|
|
|
|
}
|