mirror of https://github.com/actions/toolkit
takost/update-github-package
parent
774f139bef
commit
f699b96ecf
|
@ -1,6 +1,7 @@
|
|||
import * as http from 'http'
|
||||
import * as https from 'https'
|
||||
import proxy from 'proxy'
|
||||
import { ProxyServer, createProxy } from "proxy";
|
||||
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
||||
|
||||
// Default values are set when the module is imported, so we need to set proxy first.
|
||||
const proxyUrl = 'http://127.0.0.1:8081'
|
||||
|
@ -16,7 +17,7 @@ describe('@actions/github', () => {
|
|||
|
||||
beforeAll(async () => {
|
||||
// Start proxy server
|
||||
proxyServer = proxy()
|
||||
proxyServer = createProxy()
|
||||
await new Promise<void>(resolve => {
|
||||
const port = Number(proxyUrl.split(':')[2])
|
||||
proxyServer.listen(port, () => resolve())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as http from 'http'
|
||||
import proxy from 'proxy'
|
||||
import { createProxy } from 'proxy'
|
||||
import {getOctokit} from '../src/github'
|
||||
import {GitHub, getOctokitOptions} from '../src/utils'
|
||||
|
||||
|
@ -12,7 +12,7 @@ describe('@actions/github', () => {
|
|||
|
||||
beforeAll(async () => {
|
||||
// Start proxy server
|
||||
proxyServer = proxy()
|
||||
proxyServer = createProxy()
|
||||
await new Promise<void>(resolve => {
|
||||
const port = Number(proxyUrl.split(':')[2])
|
||||
proxyServer.listen(port, () => resolve())
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@actions/github",
|
||||
"version": "5.1.1",
|
||||
"version": "6.0.0",
|
||||
"description": "Actions github lib",
|
||||
"keywords": [
|
||||
"github",
|
||||
|
@ -38,12 +38,14 @@
|
|||
"url": "https://github.com/actions/toolkit/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"@octokit/core": "^3.6.0",
|
||||
"@octokit/plugin-paginate-rest": "^2.17.0",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^5.13.0"
|
||||
"@actions/http-client": "file:../actions-http-client-3.0.1.tgz",
|
||||
"@octokit/core": "^4.2.4",
|
||||
"@octokit/plugin-paginate-rest": "^6.1.2",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^7.2.3",
|
||||
"undici": "^5.25.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"proxy": "^1.0.2"
|
||||
"@types/proxy": "^1.0.1",
|
||||
"proxy": "^2.1.1"
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import * as http from 'http'
|
||||
import * as httpClient from '@actions/http-client'
|
||||
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
||||
import { ProxyAgent, Agent, fetch as undiciFetch } from "undici";
|
||||
|
||||
export function getAuthString(
|
||||
token: string,
|
||||
|
@ -20,6 +21,22 @@ export function getProxyAgent(destinationUrl: string): http.Agent {
|
|||
return hc.getAgent(destinationUrl)
|
||||
}
|
||||
|
||||
export function getProxyAgentDispatcher(destinationUrl: string): ProxyAgent | undefined {
|
||||
const hc = new httpClient.HttpClient()
|
||||
return hc.getAgentDispatcher(destinationUrl)
|
||||
}
|
||||
|
||||
export function getProxyFetch(destinationUrl): any {
|
||||
const httpAgent = getProxyAgentDispatcher(destinationUrl)
|
||||
const proxyFetch: typeof undiciFetch = (url, opts) => {
|
||||
return undiciFetch(url, {
|
||||
...opts,
|
||||
dispatcher: httpAgent,
|
||||
});
|
||||
};
|
||||
return proxyFetch;
|
||||
}
|
||||
|
||||
export function getApiBaseUrl(): string {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ const baseUrl = Utils.getApiBaseUrl()
|
|||
export const defaults: OctokitOptions = {
|
||||
baseUrl,
|
||||
request: {
|
||||
agent: Utils.getProxyAgent(baseUrl)
|
||||
agent: Utils.getProxyAgent(baseUrl),
|
||||
fetch: Utils.getProxyFetch(baseUrl)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -299,7 +299,7 @@ describe('proxy', () => {
|
|||
it('proxy settings return ProxyAgent', async () => {
|
||||
process.env['https_proxy'] = 'http://127.0.0.1:8080'
|
||||
const httpClient = new httpm.HttpClient()
|
||||
const agent: Agent | ProxyAgent = httpClient.getAgentDispatcher('https://some-url')
|
||||
const agent = httpClient.getAgentDispatcher('https://some-url')
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(agent)
|
||||
expect(agent instanceof ProxyAgent).toBe(true)
|
||||
|
@ -307,10 +307,10 @@ describe('proxy', () => {
|
|||
|
||||
it('proxyAuth is set in tunnel agent when authentication is provided', async () => {
|
||||
const httpClient = new httpm.HttpClient()
|
||||
const agent: Agent | ProxyAgent = httpClient.getAgentDispatcher('https://some-url')
|
||||
const agent = httpClient.getAgentDispatcher('https://some-url')
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(agent)
|
||||
expect(agent instanceof Agent).toBe(true)
|
||||
expect(agent).toBe(undefined)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@actions/http-client",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"description": "Actions Http Client",
|
||||
"keywords": [
|
||||
"github",
|
||||
|
|
|
@ -567,16 +567,14 @@ export class HttpClient {
|
|||
return this._getAgent(parsedUrl)
|
||||
}
|
||||
|
||||
getAgentDispatcher(serverUrl: string): ProxyAgent | Agent {
|
||||
getAgentDispatcher(serverUrl: string): ProxyAgent | undefined {
|
||||
const parsedUrl = new URL(serverUrl)
|
||||
const proxyUrl = pm.getProxyUrl(parsedUrl)
|
||||
const useProxy = proxyUrl && proxyUrl.hostname
|
||||
if (useProxy) {
|
||||
return this._getProxyAgentDispatcher(parsedUrl, proxyUrl)
|
||||
}
|
||||
else {
|
||||
return this._getAgentDispatcher(parsedUrl)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private _prepareRequest(
|
||||
|
@ -763,46 +761,6 @@ export class HttpClient {
|
|||
return proxyAgent
|
||||
}
|
||||
|
||||
private _getAgentDispatcher(parsedUrl: URL): Agent {
|
||||
let agent;
|
||||
|
||||
if (this._keepAlive) {
|
||||
agent = this._agentDispatcher
|
||||
}
|
||||
|
||||
// if agent is already assigned use that agent.
|
||||
if (agent) {
|
||||
return agent
|
||||
}
|
||||
|
||||
const usingSsl = parsedUrl.protocol === 'https:'
|
||||
let maxSockets = 100
|
||||
if (this.requestOptions) {
|
||||
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets
|
||||
}
|
||||
|
||||
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
||||
if (!agent) {
|
||||
agent = new Agent(
|
||||
{
|
||||
pipelining: (!this._keepAlive ? 0 : 1),
|
||||
}
|
||||
)
|
||||
this._agentDispatcher = agent
|
||||
}
|
||||
|
||||
if (usingSsl && this._ignoreSslError) {
|
||||
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
||||
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
||||
// we have to cast it to any and change it directly
|
||||
agent.options = Object.assign(agent.options.connect || {}, {
|
||||
rejectUnauthorized: false
|
||||
})
|
||||
}
|
||||
|
||||
return agent
|
||||
}
|
||||
|
||||
private async _performExponentialBackoff(retryNumber: number): Promise<void> {
|
||||
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
|
||||
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)
|
||||
|
|
Loading…
Reference in New Issue