Merge pull request #122 from xie-jinwei/proxy

feat: add support for proxy
This commit is contained in:
Peter Evans
2021-09-02 13:13:27 +09:00
committed by GitHub
4 changed files with 2071 additions and 123 deletions
+2043 -113
View File
File diff suppressed because it is too large Load Diff
+2 -8
View File
@@ -1186,8 +1186,7 @@
"@tootallnate/once": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz",
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
"dev": true
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw=="
},
"@types/babel__core": {
"version": "7.1.15",
@@ -1449,7 +1448,6 @@
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
"dev": true,
"requires": {
"debug": "4"
}
@@ -1906,7 +1904,6 @@
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
"integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"dev": true,
"requires": {
"ms": "2.1.2"
}
@@ -2823,7 +2820,6 @@
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz",
"integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==",
"dev": true,
"requires": {
"@tootallnate/once": "1",
"agent-base": "6",
@@ -2834,7 +2830,6 @@
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
"integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==",
"dev": true,
"requires": {
"agent-base": "6",
"debug": "4"
@@ -4679,8 +4674,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=="
},
"natural-compare": {
"version": "1.4.0",
+3 -1
View File
@@ -32,7 +32,9 @@
"@actions/github": "5.0.0",
"@octokit/core": "3.5.1",
"@octokit/plugin-paginate-rest": "2.14.0",
"@octokit/plugin-rest-endpoint-methods": "5.5.0"
"@octokit/plugin-rest-endpoint-methods": "5.5.0",
"http-proxy-agent": "4.0.1",
"https-proxy-agent": "5.0.0"
},
"devDependencies": {
"@types/jest": "26.0.24",
+23 -1
View File
@@ -4,8 +4,30 @@ import {
restEndpointMethods,
RestEndpointMethodTypes
} from '@octokit/plugin-rest-endpoint-methods'
import {HttpProxyAgent} from 'http-proxy-agent'
import {HttpsProxyAgent} from 'https-proxy-agent'
export const Octokit = Core.plugin(paginateRest, restEndpointMethods)
export const Octokit = Core.plugin(
paginateRest,
restEndpointMethods,
autoProxyAgent
)
export type PullsGetResponseData =
RestEndpointMethodTypes['pulls']['get']['response']['data']
// Octokit plugin to support the http_proxy and https_proxy environment variable
function autoProxyAgent(octokit: Core) {
const http_proxy_address =
process.env['http_proxy'] || process.env['HTTP_PROXY']
const https_proxy_address =
process.env['https_proxy'] || process.env['HTTPS_PROXY']
octokit.hook.before('request', options => {
if (options.baseUrl.startsWith('http://') && http_proxy_address) {
options.request.agent = new HttpProxyAgent(http_proxy_address)
} else if (options.baseUrl.startsWith('https://') && https_proxy_address) {
options.request.agent = new HttpsProxyAgent(https_proxy_address)
}
})
}