From b37c8075f683a817e70300e6adc7e0137a6d96e2 Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 24 Aug 2022 03:06:26 +0800 Subject: [PATCH 1/3] Upgrade http-proxy-agent and https-proxy-agent - Upgraded http-proxy-agent to ^5.0.0 - Upgraded https-proxy-agent to ^5.0.1 - Removed replaced types: @types/http-proxy-agent - Removed replaced type declaration for https-proxy-agent - Removed use of new for agent initialization - Work around private property access in testsby using string index notation for agent['proxy'] --- package.json | 5 ++- source/api/_tests/fetch.test.ts | 12 +++---- source/api/fetch.ts | 2 +- source/https-proxy-agent.d.ts | 24 ------------- yarn.lock | 61 +++++++-------------------------- 5 files changed, 22 insertions(+), 82 deletions(-) delete mode 100644 source/https-proxy-agent.d.ts diff --git a/package.json b/package.json index d2f60e19b..edbe59261 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,6 @@ "@types/async-retry": "^1.4.1", "@types/debug": "0.0.30", "@types/get-stdin": "^5.0.1", - "@types/http-proxy-agent": "^2.0.1", "@types/jest": "^24.0.11", "@types/json5": "^0.0.30", "@types/jsonpointer": "^4.0.0", @@ -151,8 +150,8 @@ "fast-json-patch": "^3.0.0-1", "get-stdin": "^6.0.0", "gitlab": "^10.0.1", - "http-proxy-agent": "^2.1.0", - "https-proxy-agent": "^2.2.1", + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.1", "hyperlinker": "^1.0.0", "json5": "^2.1.0", "jsonpointer": "^5.0.0", diff --git a/source/api/_tests/fetch.test.ts b/source/api/_tests/fetch.test.ts index a28d735b6..086fe33ab 100644 --- a/source/api/_tests/fetch.test.ts +++ b/source/api/_tests/fetch.test.ts @@ -1,9 +1,9 @@ import * as http from "http" import * as node_fetch from "node-fetch" +import type { HttpProxyAgent } from "http-proxy-agent" +import type { HttpsProxyAgent } from "https-proxy-agent" import { api } from "../fetch" -import HttpProxyAgent from "http-proxy-agent" -import HttpsProxyAgent from "http-proxy-agent" interface ResponseMock { body?: any @@ -128,7 +128,7 @@ describe("fetch", () => { let options: node_fetch.RequestInit = { agent: undefined } await api(url, options, true, { HTTPS_PROXY: proxyUrl }) let agent = options.agent as HttpsProxyAgent - expect(agent.proxy.href).toBe(proxyUrl) + expect(agent["proxy"].href).toBe(proxyUrl) }) it("sets proxy agent when https_proxy env variable is defined", async () => { @@ -140,7 +140,7 @@ describe("fetch", () => { let options: node_fetch.RequestInit = { agent: undefined } await api(url, options, true, { https_proxy: proxyUrl }) let agent = options.agent as HttpsProxyAgent - expect(agent.proxy.href).toBe(proxyUrl) + expect(agent["proxy"].href).toBe(proxyUrl) }) it("sets proxy agent when HTTP_PROXY env variable is defined", async () => { @@ -152,7 +152,7 @@ describe("fetch", () => { let options: node_fetch.RequestInit = { agent: undefined } await api(url, options, true, { HTTP_PROXY: proxyUrl }) let agent = options.agent as HttpProxyAgent - expect(agent.proxy.href).toBe(proxyUrl) + expect(agent["proxy"].href).toBe(proxyUrl) }) it("sets proxy agent when http_proxy env variable is defined", async () => { @@ -164,6 +164,6 @@ describe("fetch", () => { let options: node_fetch.RequestInit = { agent: undefined } await api(url, options, true, { http_proxy: proxyUrl }) let agent = options.agent as HttpProxyAgent - expect(agent.proxy.href).toBe(proxyUrl) + expect(agent["proxy"].href).toBe(proxyUrl) }) }) diff --git a/source/api/fetch.ts b/source/api/fetch.ts index 795f0ea70..2afd2eb65 100644 --- a/source/api/fetch.ts +++ b/source/api/fetch.ts @@ -113,7 +113,7 @@ export function api( if (!agent && proxy) { let secure = url.toString().startsWith("https") - init.agent = secure ? new HttpsProxyAgent(proxy) : new HttpProxyAgent(proxy) + init.agent = secure ? HttpsProxyAgent(proxy) : HttpProxyAgent(proxy) } return retryableFetch(url, init).then(async (response: node_fetch.Response) => { diff --git a/source/https-proxy-agent.d.ts b/source/https-proxy-agent.d.ts deleted file mode 100644 index 3782d46fe..000000000 --- a/source/https-proxy-agent.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -// From: https://github.com/TooTallNate/node-https-proxy-agent/issues/27 -declare module "https-proxy-agent" { - import * as https from "https" - - namespace HttpsProxyAgent { - interface HttpsProxyAgentOptions { - host: string - port: number - secureProxy?: boolean - headers?: { - [key: string]: string - } - [key: string]: any - } - } - - // HttpsProxyAgent doesnt *actually* extend https.Agent, but for my purposes I want it to pretend that it does - class HttpsProxyAgent extends https.Agent { - constructor(opts: string) - constructor(opts: HttpsProxyAgent.HttpsProxyAgentOptions) - } - - export = HttpsProxyAgent -} diff --git a/yarn.lock b/yarn.lock index c993c49ad..60f0dc0b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1453,6 +1453,11 @@ dependencies: defer-to-connect "^2.0.0" +"@tootallnate/once@2": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" + integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A== + "@tsconfig/node10@^1.0.7": version "1.0.8" resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" @@ -1529,13 +1534,6 @@ resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz#9140779736aa2655635ee756e2467d787cfe8a2a" integrity sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A== -"@types/http-proxy-agent@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@types/http-proxy-agent/-/http-proxy-agent-2.0.1.tgz#2f95077f6bfe7adc39cc0f0042da85997ae77fc7" - integrity sha512-dgsgbsgI3t+ZkdzF9H19uBaLsurIZJJjJsVpj4mCLp8B6YghQ7jVwyqhaL0PcVtuC3nOi0ZBhAi2Dd9jCUwdFA== - dependencies: - "@types/node" "*" - "@types/jest-diff@*": version "20.0.1" resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" @@ -1862,13 +1860,6 @@ address@^1.0.1: resolved "https://registry.yarnpkg.com/address/-/address-1.0.3.tgz#b5f50631f8d6cec8bd20c963963afb55e06cbce9" integrity sha512-z55ocwKBRLryBs394Sm3ushTtBeg6VAeuku7utSoSnsJKvKcnXFIyC6vh27n3rXyxSgkJBBCAvyOn7gSUcTYjg== -agent-base@4, agent-base@^4.1.0: - version "4.2.1" - resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9" - integrity sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg== - dependencies: - es6-promisify "^5.0.0" - agent-base@6: version "6.0.2" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" @@ -3281,13 +3272,6 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0: dependencies: ms "2.0.0" -debug@3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" - integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== - dependencies: - ms "2.0.0" - debug@4, debug@^4.0.0, debug@^4.3.1: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" @@ -3751,18 +3735,6 @@ es-to-primitive@^1.1.1: is-date-object "^1.0.1" is-symbol "^1.0.1" -es6-promise@^4.0.3: - version "4.2.5" - resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.5.tgz#da6d0d5692efb461e082c14817fe2427d8f5d054" - integrity sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg== - -es6-promisify@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203" - integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM= - dependencies: - es6-promise "^4.0.3" - escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -5035,13 +5007,14 @@ http-errors@~1.6.1: setprototypeof "1.0.3" statuses ">= 1.3.1 < 2" -http-proxy-agent@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-2.1.0.tgz#e4821beef5b2142a2026bd73926fe537631c5405" - integrity sha512-qwHbBLV7WviBl0rQsOzH6o5lwyOIvwp/BdFnvVxXORldu5TmjFfjzBcWUWS5kWAZhmv+JtiDhSuQCp4sBfbIgg== +http-proxy-agent@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz#5129800203520d434f142bc78ff3c170800f2b43" + integrity sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w== dependencies: - agent-base "4" - debug "3.1.0" + "@tootallnate/once" "2" + agent-base "6" + debug "4" http-signature@~1.2.0: version "1.2.0" @@ -5052,15 +5025,7 @@ http-signature@~1.2.0: jsprim "^1.2.2" sshpk "^1.7.0" -https-proxy-agent@^2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0" - integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ== - dependencies: - agent-base "^4.1.0" - debug "^3.1.0" - -https-proxy-agent@^5.0.0: +https-proxy-agent@^5.0.0, https-proxy-agent@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz#c59ef224a04fe8b754f3db0063a25ea30d0005d6" integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA== From d015c09c5bf06876cfd950092614d3bafb8778c9 Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 24 Aug 2022 03:11:00 +0800 Subject: [PATCH 2/3] Fixed syntax --- .../bitbucket_cloud/BitBucketCloudAPI.ts | 20 ++++++++++--------- .../bitbucket_server/BitBucketServerAPI.ts | 19 +++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts b/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts index 16796c477..f0d6f333a 100644 --- a/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts +++ b/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts @@ -219,20 +219,22 @@ export class BitBucketCloudAPI { const dangerIDMessage = dangerIDToString(dangerID) return comments - .filter(comment => comment.inline == null) - .filter(comment => comment.content.raw.includes(dangerIDMessage)) - .filter(comment => comment.user.uuid === this.uuid) + .filter((comment) => comment.inline == null) + .filter((comment) => comment.content.raw.includes(dangerIDMessage)) + .filter((comment) => comment.user.uuid === this.uuid) } getDangerInlineComments = async (dangerID: string): Promise => { const comments = await this.getPullRequestComments() const dangerIDMessage = dangerIDToString(dangerID) - return comments.filter(comment => comment.inline).map(comment => ({ - id: comment.id.toString(), - ownedByDanger: comment.content.raw.includes(dangerIDMessage) && comment.user.uuid === this.uuid, - body: comment.content.raw, - })) + return comments + .filter((comment) => comment.inline) + .map((comment) => ({ + id: comment.id.toString(), + ownedByDanger: comment.content.raw.includes(dangerIDMessage) && comment.user.uuid === this.uuid, + body: comment.content.raw, + })) } postBuildStatus = async ( @@ -370,7 +372,7 @@ export class BitBucketCloudAPI { let agent: Agent | undefined = undefined let proxy = process.env.http_proxy || process.env.https_proxy if (proxy) { - agent = new HttpsProxyAgent(proxy) + agent = HttpsProxyAgent(proxy) } return this.fetch( diff --git a/source/platforms/bitbucket_server/BitBucketServerAPI.ts b/source/platforms/bitbucket_server/BitBucketServerAPI.ts index 074bd732d..a05348ce6 100644 --- a/source/platforms/bitbucket_server/BitBucketServerAPI.ts +++ b/source/platforms/bitbucket_server/BitBucketServerAPI.ts @@ -209,12 +209,12 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { const activities = await this.getPullRequestComments() const dangerIDMessage = dangerIDToString(dangerID) - const comments = activities.map(activity => activity.comment).filter(Boolean) as BitBucketServerPRComment[] + const comments = activities.map((activity) => activity.comment).filter(Boolean) as BitBucketServerPRComment[] return comments - .filter(comment => comment!.text.includes(dangerIDMessage)) - .filter(comment => comment!.author.name.toLowerCase() === username!.toLowerCase()) - .filter(comment => comment!.text.includes("Generated by")) + .filter((comment) => comment!.text.includes(dangerIDMessage)) + .filter((comment) => comment!.author.name.toLowerCase() === username!.toLowerCase()) + .filter((comment) => comment!.text.includes("Generated by")) } getDangerInlineComments = async (dangerID: string): Promise => { @@ -223,16 +223,17 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { const dangerIDMessage = dangerIDToString(dangerID) const comments = activities - .filter(activity => activity.commentAnchor) - .map(activity => activity.comment) + .filter((activity) => activity.commentAnchor) + .map((activity) => activity.comment) .filter(Boolean) as BitBucketServerPRComment[] - return new Promise(resolve => { + return new Promise((resolve) => { resolve( comments .map((i: any) => { return { id: i.id, - ownedByDanger: i.author.name.toLowerCase() === username!.toLowerCase() && i.text.includes(dangerIDMessage), + ownedByDanger: + i.author.name.toLowerCase() === username!.toLowerCase() && i.text.includes(dangerIDMessage), body: i.text, } }) @@ -353,7 +354,7 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { let agent: Agent | undefined = undefined let proxy = process.env.http_proxy || process.env.https_proxy if (proxy) { - agent = new HttpsProxyAgent(proxy) + agent = HttpsProxyAgent(proxy) } return this.fetch( From 8dd9fd8b51c7df57b3c8492209d6d5a4676f9d6c Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 24 Aug 2022 03:29:40 +0800 Subject: [PATCH 3/3] Revert unrelated formatting changes --- .../bitbucket_cloud/BitBucketCloudAPI.ts | 18 ++++++++---------- .../bitbucket_server/BitBucketServerAPI.ts | 17 ++++++++--------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts b/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts index f0d6f333a..0bace9b9d 100644 --- a/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts +++ b/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts @@ -219,22 +219,20 @@ export class BitBucketCloudAPI { const dangerIDMessage = dangerIDToString(dangerID) return comments - .filter((comment) => comment.inline == null) - .filter((comment) => comment.content.raw.includes(dangerIDMessage)) - .filter((comment) => comment.user.uuid === this.uuid) + .filter(comment => comment.inline == null) + .filter(comment => comment.content.raw.includes(dangerIDMessage)) + .filter(comment => comment.user.uuid === this.uuid) } getDangerInlineComments = async (dangerID: string): Promise => { const comments = await this.getPullRequestComments() const dangerIDMessage = dangerIDToString(dangerID) - return comments - .filter((comment) => comment.inline) - .map((comment) => ({ - id: comment.id.toString(), - ownedByDanger: comment.content.raw.includes(dangerIDMessage) && comment.user.uuid === this.uuid, - body: comment.content.raw, - })) + return comments.filter(comment => comment.inline).map(comment => ({ + id: comment.id.toString(), + ownedByDanger: comment.content.raw.includes(dangerIDMessage) && comment.user.uuid === this.uuid, + body: comment.content.raw, + })) } postBuildStatus = async ( diff --git a/source/platforms/bitbucket_server/BitBucketServerAPI.ts b/source/platforms/bitbucket_server/BitBucketServerAPI.ts index a05348ce6..554edadc4 100644 --- a/source/platforms/bitbucket_server/BitBucketServerAPI.ts +++ b/source/platforms/bitbucket_server/BitBucketServerAPI.ts @@ -209,12 +209,12 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { const activities = await this.getPullRequestComments() const dangerIDMessage = dangerIDToString(dangerID) - const comments = activities.map((activity) => activity.comment).filter(Boolean) as BitBucketServerPRComment[] + const comments = activities.map(activity => activity.comment).filter(Boolean) as BitBucketServerPRComment[] return comments - .filter((comment) => comment!.text.includes(dangerIDMessage)) - .filter((comment) => comment!.author.name.toLowerCase() === username!.toLowerCase()) - .filter((comment) => comment!.text.includes("Generated by")) + .filter(comment => comment!.text.includes(dangerIDMessage)) + .filter(comment => comment!.author.name.toLowerCase() === username!.toLowerCase()) + .filter(comment => comment!.text.includes("Generated by")) } getDangerInlineComments = async (dangerID: string): Promise => { @@ -223,17 +223,16 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { const dangerIDMessage = dangerIDToString(dangerID) const comments = activities - .filter((activity) => activity.commentAnchor) - .map((activity) => activity.comment) + .filter(activity => activity.commentAnchor) + .map(activity => activity.comment) .filter(Boolean) as BitBucketServerPRComment[] - return new Promise((resolve) => { + return new Promise(resolve => { resolve( comments .map((i: any) => { return { id: i.id, - ownedByDanger: - i.author.name.toLowerCase() === username!.toLowerCase() && i.text.includes(dangerIDMessage), + ownedByDanger: i.author.name.toLowerCase() === username!.toLowerCase() && i.text.includes(dangerIDMessage), body: i.text, } })