This commit is contained in:
Tatyana Kostromskaya
2023-10-04 09:30:46 +00:00
parent c25ba9aa99
commit 71bc34b2d5
10 changed files with 725 additions and 431 deletions

View File

@@ -1,6 +1,5 @@
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";
@@ -18,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())
@@ -50,22 +49,7 @@ describe('@actions/github', () => {
return
}
const myFetch: typeof undiciFetch = (url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: new ProxyAgent({
uri: proxyUrl,
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10,
}),
});
};
const octokit = getOctokit(token, {
request: {
fetch: myFetch
}
})
const octokit = getOctokit(token)
const branch = await octokit.rest.repos.getBranch({
owner: 'actions',
@@ -82,22 +66,18 @@ describe('@actions/github', () => {
return
}
process.env['https_proxy'] = proxyUrl
const myFetch: typeof undiciFetch = (url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: new ProxyAgent({
uri: proxyUrl,
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10,
}),
});
};
// const myFetch: typeof undiciFetch = (url, opts) => {
// return undiciFetch(url, {
// ...opts,
// dispatcher: new ProxyAgent({
// uri: proxyUrl,
// keepAliveTimeout: 10,
// keepAliveMaxTimeout: 10,
// }),
// });
// };
const octokit = getOctokit(token, {
request: {
fetch: myFetch
}
})
const octokit = getOctokit(token)
const repository = await octokit.graphql(
'{repository(owner:"actions", name:"toolkit"){name}}'

View File

@@ -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

View File

@@ -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:../http-client/actions-http-client-3.0.0.tgz",
"@octokit/core": "^4.2.4",
"@octokit/plugin-paginate-rest": "^6.1.2",
"@octokit/plugin-rest-endpoint-methods": "^7.2.3"
},
"devDependencies": {
"proxy": "^1.0.2"
"@types/proxy": "^1.0.1",
"proxy": "^2.1.1",
"undici": "^5.25.2"
}
}
}

View File

@@ -2,7 +2,7 @@ import * as http from 'http'
import * as httpClient from '@actions/http-client'
import {OctokitOptions} from '@octokit/core/dist-types/types'
import { ProxyServer, createProxy } from "proxy";
import { ProxyAgent, fetch as undiciFetch } from "undici";
import { ProxyAgent, Agent, fetch as undiciFetch } from "undici";
export function getAuthString(
token: string,
@@ -22,15 +22,17 @@ export function getProxyAgent(destinationUrl: string): http.Agent {
return hc.getAgent(destinationUrl)
}
export function getNewProxyAgent(destinationUrl: string): ProxyAgent | Agent {
const hc = new httpClient.HttpClient()
return hc.getNewAgent(destinationUrl)
}
export function getProxyFetchAgent(destinationUrl): any {
const httpAgent = getNewProxyAgent(destinationUrl)
const myFetch: typeof undiciFetch = (url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: new ProxyAgent({
uri: destinationUrl,
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10,
}),
dispatcher: httpAgent,
});
};
return myFetch;