From 3fd4ef61b552ec92df895268e7af32760b7de51c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 18 Jul 2023 13:42:55 -0700 Subject: [PATCH] fix(deps): update octokit monorepo (major) (#513) * fix(deps): update octokit monorepo * todo fix proxy test by replacing http agent/fetch mock with custom fetch * build: switch to `@gr2m/fetch-mock` * updates the plugin to use a custom fetch as suggested * moves undici to deps and removes https-proxy-agent * Serialization issue as seen in core * adds local server for the tests to call * Undo skip for array of smoke tests * Undo skip on another test * WIP checkpoint with all lines covered but one test broken * WIP checkpoint with tests passing * Use localhost for consistency * Remove extraneous console.log statements * Strongly type Server * Some test cleanup * WIP comment out spy * Refactor customFetch tests to own describe block * Comment fix * Remove redundant tests * Remove unnecessary tests * Revert "Remove unnecessary tests" This reverts commit 645878570c1142884177382ea14a62703146313f in order to increase code coverage. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com> Co-authored-by: wolfy1339 Co-authored-by: Keegan Campbell --- package-lock.json | 255 +++++++++++++++++++-------------------------- package.json | 14 +-- src/index.ts | 17 ++- test/smoke.test.ts | 138 ++++++++++++++++-------- 4 files changed, 223 insertions(+), 201 deletions(-) diff --git a/package-lock.json b/package-lock.json index d0a3c00c..59e55380 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,19 +9,19 @@ "version": "0.0.0-development", "license": "MIT", "dependencies": { - "@octokit/auth-action": "^3.0.0", - "@octokit/core": "^4.0.0", - "@octokit/plugin-paginate-rest": "^7.0.0", - "@octokit/plugin-rest-endpoint-methods": "^8.0.0", - "@octokit/types": "^10.0.0", - "https-proxy-agent": "^7.0.0" + "@octokit/auth-action": "^4.0.0", + "@octokit/core": "^5.0.0", + "@octokit/plugin-paginate-rest": "^8.0.0", + "@octokit/plugin-rest-endpoint-methods": "^9.0.0", + "@octokit/types": "^11.0.0", + "undici": "^5.0.0" }, "devDependencies": { "@octokit/tsconfig": "^2.0.0", "@types/jest": "^29.0.0", "@types/node": "^18.0.0", "esbuild": "^0.18.0", - "fetch-mock": "^9.0.0", + "fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1", "glob": "^10.2.6", "jest": "^29.0.0", "prettier": "3.0.0", @@ -1506,12 +1506,12 @@ "dev": true }, "node_modules/@octokit/auth-action": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-3.0.2.tgz", - "integrity": "sha512-QkRAlAFqELFdzddFjDA68IN26pJ2hoTLY2vNYsmX5vwcYIWiiQA1KDFIrqpdzZo4dpPJXM9E0drXyBpZhicGTA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-4.0.0.tgz", + "integrity": "sha512-sMm9lWZdiX6e89YFaLrgE9EFs94k58BwIkvjOtozNWUqyTmsrnWFr/M5LolaRzZ7Kmb5FbhF9hi7FEeE274SoQ==", "dependencies": { "@octokit/auth-token": "^4.0.0", - "@octokit/types": "^10.0.0" + "@octokit/types": "^11.0.0" }, "engines": { "node": ">= 18" @@ -1526,78 +1526,46 @@ } }, "node_modules/@octokit/core": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-4.2.4.tgz", - "integrity": "sha512-rYKilwgzQ7/imScn3M9/pFfUf4I1AZEH3KhyJmtPdE2zfaXAn2mFfUy4FbKewzc2We5y/LlKLj36fWJLKC2SIQ==", - "dependencies": { - "@octokit/auth-token": "^3.0.0", - "@octokit/graphql": "^5.0.0", - "@octokit/request": "^6.0.0", - "@octokit/request-error": "^3.0.0", - "@octokit/types": "^9.0.0", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.0.0.tgz", + "integrity": "sha512-YbAtMWIrbZ9FCXbLwT9wWB8TyLjq9mxpKdgB3dUNxQcIVTf9hJ70gRPwAcqGZdY6WdJPZ0I7jLaaNDCiloGN2A==", + "dependencies": { + "@octokit/auth-token": "^4.0.0", + "@octokit/graphql": "^7.0.0", + "@octokit/request": "^8.0.2", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^11.0.0", "before-after-hook": "^2.2.0", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/core/node_modules/@octokit/auth-token": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-3.0.4.tgz", - "integrity": "sha512-TWFX7cZF2LXoCvdmJWY7XVPi74aSY0+FfBZNSXEXFkMpjcqsQwDSYVv5FhRFaI0V1ECnwbz4j59T/G+rXNWaIQ==", - "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/core/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/endpoint": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-7.0.6.tgz", - "integrity": "sha512-5L4fseVRUsDFGR00tMWD/Trdeeihn999rTMGRMC1G/Ldi1uWlWJzI98H4Iak5DB/RVvQuyMYKqSK/R6mbSOQyg==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.0.tgz", + "integrity": "sha512-szrQhiqJ88gghWY2Htt8MqUDO6++E/EIXqJ2ZEp5ma3uGS46o7LZAzSLt49myB7rT+Hfw5Y6gO3LmOxGzHijAQ==", "dependencies": { - "@octokit/types": "^9.0.0", + "@octokit/types": "^11.0.0", "is-plain-object": "^5.0.0", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/endpoint/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/graphql": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.6.tgz", - "integrity": "sha512-Fxyxdy/JH0MnIB5h+UQ3yCoh1FG4kWXfFKkpWqjZHw/p+Kc8Y44Hu/kCgNBT6nU1shNumEchmW/sUO1JuQnPcw==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.0.1.tgz", + "integrity": "sha512-T5S3oZ1JOE58gom6MIcrgwZXzTaxRnxBso58xhozxHpOqSTgDS6YNeEUvZ/kRvXgPrRz/KHnZhtb7jUMRi9E6w==", "dependencies": { - "@octokit/request": "^6.0.0", - "@octokit/types": "^9.0.0", + "@octokit/request": "^8.0.1", + "@octokit/types": "^11.0.0", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/graphql/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/openapi-types": { @@ -1606,96 +1574,71 @@ "integrity": "sha512-V8GImKs3TeQRxRtXFpG2wl19V7444NIOTDF24AWuIbmNaNYOQMWRbjcGDXV5B+0n887fgDcuMNOmlul+k+oJtw==" }, "node_modules/@octokit/plugin-paginate-rest": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-7.1.2.tgz", - "integrity": "sha512-Jx8KuKqEAVRsK6fMzZKv3h6UH9/NRDHsDRtUAROqqmZlCptM///Uef7A1ViZ/cbDplekz7VbDWdFLAZ/mpuDww==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-8.0.0.tgz", + "integrity": "sha512-2xZ+baZWUg+qudVXnnvXz7qfrTmDeYPCzangBVq/1gXxii/OiS//4shJp9dnCCvj1x+JAm9ji1Egwm1BA47lPQ==", "dependencies": { - "@octokit/tsconfig": "^2.0.0", - "@octokit/types": "^9.3.2" + "@octokit/types": "^11.0.0" }, "engines": { "node": ">= 18" }, "peerDependencies": { - "@octokit/core": ">=4" - } - }, - "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "@octokit/core": ">=5" } }, "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-8.0.0.tgz", - "integrity": "sha512-GtA8B7zkdxJv2OBVUtUeynu/OkWo272w2IpWC+QCQiUhgrRZ9Zrz2NgAiqYkVhlITGD3PcWYEjy9JR1HrzYtQA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-9.0.0.tgz", + "integrity": "sha512-KquMF/VB1IkKNiVnzJKspY5mFgGyLd7HzdJfVEGTJFzqu9BRFNWt+nwTCMuUiWc72gLQhRWYubTwOkQj+w/1PA==", "dependencies": { - "@octokit/types": "^10.0.0" + "@octokit/types": "^11.0.0" }, "engines": { "node": ">= 18" }, "peerDependencies": { - "@octokit/core": ">=3" + "@octokit/core": ">=5" } }, "node_modules/@octokit/request": { - "version": "6.2.8", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.8.tgz", - "integrity": "sha512-ow4+pkVQ+6XVVsekSYBzJC0VTVvh/FCTUUgTsboGq+DTeWdyIFV8WSCdo0RIxk6wSkBTHqIK1mYuY7nOBXOchw==", + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.0.4.tgz", + "integrity": "sha512-YZ1XeDRil4ejHKoBP8BgROgP4auOH5A9lLZH96l39GKKEmsKOccQxKP5M7m+Punblg1bFw8LrdeKIDwIzQ8afA==", "dependencies": { - "@octokit/endpoint": "^7.0.0", - "@octokit/request-error": "^3.0.0", - "@octokit/types": "^9.0.0", + "@octokit/endpoint": "^9.0.0", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^11.0.0", "is-plain-object": "^5.0.0", - "node-fetch": "^2.6.7", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 18" } }, "node_modules/@octokit/request-error": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-3.0.3.tgz", - "integrity": "sha512-crqw3V5Iy2uOU5Np+8M/YexTlT8zxCfI+qu+LxUB7SZpje4Qmx3mub5DfEKSO8Ylyk0aogi6TYdf6kxzh2BguQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.0.0.tgz", + "integrity": "sha512-1ue0DH0Lif5iEqT52+Rf/hf0RmGO9NWFjrzmrkArpG9trFfDM/efx00BJHdLGuro4BR/gECxCU2Twf5OKrRFsQ==", "dependencies": { - "@octokit/types": "^9.0.0", + "@octokit/types": "^11.0.0", "deprecation": "^2.0.0", "once": "^1.4.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/request-error/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" - } - }, - "node_modules/@octokit/request/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/tsconfig": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-2.0.0.tgz", - "integrity": "sha512-tWnrai3quGt8+gRN2edzo9fmraWekeryXPeXDomMw2oFSpu/lH3VSWGn/q4V+rwjTRMeeXk/ci623/01Zet4VQ==" + "integrity": "sha512-tWnrai3quGt8+gRN2edzo9fmraWekeryXPeXDomMw2oFSpu/lH3VSWGn/q4V+rwjTRMeeXk/ci623/01Zet4VQ==", + "dev": true }, "node_modules/@octokit/types": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-10.0.0.tgz", - "integrity": "sha512-Vm8IddVmhCgU1fxC1eyinpwqzXPEYu0NrYzD3YZjlGjyftdLBTeqNblRC0jmJmgxbJIsQlyogVeGnrNaaMVzIg==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-11.1.0.tgz", + "integrity": "sha512-Fz0+7GyLm/bHt8fwEqgvRBWwIV1S6wRRyq+V6exRKLVWaKGsuy6H9QFYeBVDV7rK6fO3XwHgQOPxv+cLj2zpXQ==", "dependencies": { "@octokit/openapi-types": "^18.0.0" } @@ -1851,17 +1794,6 @@ "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", "dev": true }, - "node_modules/agent-base": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", - "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", - "dependencies": { - "debug": "^4.3.4" - }, - "engines": { - "node": ">= 14" - } - }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -2108,6 +2040,17 @@ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "dev": true }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2339,6 +2282,7 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -2566,9 +2510,10 @@ } }, "node_modules/fetch-mock": { - "version": "9.11.0", - "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-9.11.0.tgz", - "integrity": "sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q==", + "name": "@gr2m/fetch-mock", + "version": "9.11.0-pull-request-644.1", + "resolved": "https://registry.npmjs.org/@gr2m/fetch-mock/-/fetch-mock-9.11.0-pull-request-644.1.tgz", + "integrity": "sha512-gTp6RCHzlOXS1qRb0APfuyz48Lw/JFPa4uiar+kEgL1STsDwth75HJZ4x30tBlXMJXV8XDTDzJ2Hz9w3RWiHJA==", "dev": true, "dependencies": { "@babel/core": "^7.0.0", @@ -2800,18 +2745,6 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, - "node_modules/https-proxy-agent": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.0.tgz", - "integrity": "sha512-0euwPCRyAPSgGdzD1IVN9nJYHtBhJwb6XPfbpQcYbPCwrBidX6GzxmchnaF4sfF/jPb74Ojx5g4yTg3sixlyPw==", - "dependencies": { - "agent-base": "^7.0.2", - "debug": "4" - }, - "engines": { - "node": ">= 14" - } - }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -3943,7 +3876,8 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "node_modules/natural-compare": { "version": "1.4.0", @@ -3955,6 +3889,9 @@ "version": "2.6.11", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "dev": true, + "optional": true, + "peer": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -4495,6 +4432,14 @@ "node": ">=8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -4701,7 +4646,10 @@ "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "dev": true, + "optional": true, + "peer": true }, "node_modules/ts-jest": { "version": "29.1.0", @@ -4813,6 +4761,17 @@ "node": ">=14.17" } }, + "node_modules/undici": { + "version": "5.22.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", + "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==", + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/universal-user-agent": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", @@ -4874,12 +4833,18 @@ "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "dev": true, + "optional": true, + "peer": true }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dev": true, + "optional": true, + "peer": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" diff --git a/package.json b/package.json index 982fa582..ba8c72ff 100644 --- a/package.json +++ b/package.json @@ -24,19 +24,19 @@ "author": "Gregor Martynus (https://twitter.com/gr2m)", "license": "MIT", "dependencies": { - "@octokit/auth-action": "^3.0.0", - "@octokit/core": "^4.0.0", - "@octokit/plugin-paginate-rest": "^7.0.0", - "@octokit/plugin-rest-endpoint-methods": "^8.0.0", - "@octokit/types": "^10.0.0", - "https-proxy-agent": "^7.0.0" + "@octokit/auth-action": "^4.0.0", + "@octokit/core": "^5.0.0", + "@octokit/plugin-paginate-rest": "^8.0.0", + "@octokit/plugin-rest-endpoint-methods": "^9.0.0", + "@octokit/types": "^11.0.0", + "undici": "^5.0.0" }, "devDependencies": { "@octokit/tsconfig": "^2.0.0", "@types/jest": "^29.0.0", "@types/node": "^18.0.0", "esbuild": "^0.18.0", - "fetch-mock": "^9.0.0", + "fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1", "glob": "^10.2.6", "jest": "^29.0.0", "prettier": "3.0.0", diff --git a/src/index.ts b/src/index.ts index 09983983..f1e7e8e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-meth import { VERSION } from "./version"; import type { OctokitOptions } from "@octokit/core/dist-types/types"; -import { HttpsProxyAgent } from "https-proxy-agent"; +import { fetch as undiciFetch, ProxyAgent } from "undici"; const DEFAULTS = { authStrategy: createActionAuth, @@ -14,20 +14,27 @@ const DEFAULTS = { userAgent: `octokit-action.js/${VERSION}`, }; -function getProxyAgent() { +export function getProxyAgent() { const httpProxy = process.env["HTTP_PROXY"] || process.env["http_proxy"]; if (httpProxy) { - return new HttpsProxyAgent(httpProxy); + return new ProxyAgent(httpProxy); } const httpsProxy = process.env["HTTPS_PROXY"] || process.env["https_proxy"]; if (httpsProxy) { - return new HttpsProxyAgent(httpsProxy); + return new ProxyAgent(httpsProxy); } return undefined; } +export const customFetch = async function (url: string, opts: any) { + return await undiciFetch(url, { + dispatcher: getProxyAgent(), + ...opts, + }); +}; + export const Octokit = Core.plugin( paginateRest, legacyRestEndpointMethods, @@ -36,7 +43,7 @@ export const Octokit = Core.plugin( ...DEFAULTS, ...options, request: { - agent: getProxyAgent(), + fetch: customFetch, ...options.request, }, }; diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 69ab5bdb..7f910882 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,12 +1,43 @@ import fetchMock from "fetch-mock"; -import { RequestOptions } from "https"; -import { HttpsProxyAgent } from "https-proxy-agent"; +import { createServer, type Server } from "https"; +import { Octokit, getProxyAgent, customFetch } from "../src"; +import { ProxyAgent } from "undici"; + +// mock undici such that we can substitute our own fetch implementation +// but use the actual ProxyAgent implementation for most tests. the +// exception is "should call undiciFetch with the correct dispatcher" +// where we want to validate that a mocked ProxyAgent is passed through +// to undici.fetch. +jest.mock("undici", () => { + return { + fetch: jest.fn(), + ProxyAgent: jest.requireActual("undici").ProxyAgent, + }; +}); +const undici = jest.requireMock("undici"); -import { Octokit } from "../src"; +describe("Smoke test", () => { + let server: Server; -jest.mock("https-proxy-agent"); + beforeAll((done) => { + server = createServer( + { + requestCert: false, + rejectUnauthorized: false, + }, + (request: any, response: any) => { + expect(request.method).toEqual("GET"); + expect(request.url).toEqual("/"); + + response.writeHead(200); + response.write("ok"); + response.end(); + }, + ); + + server.listen(0, done); + }); -describe("Smoke test", () => { beforeEach(() => { delete process.env.GITHUB_TOKEN; delete process.env.INPUT_GITHUB_TOKEN; @@ -14,6 +45,30 @@ describe("Smoke test", () => { delete process.env.GITHUB_API_URL; delete process.env.HTTPS_PROXY; delete process.env.https_proxy; + delete process.env.HTTP_PROXY; + delete process.env.http_proxy; + }); + + afterAll((done) => { + server.close(done); + jest.unmock("undici"); + }); + + it("should return a ProxyAgent for the httpProxy environment variable", () => { + process.env.HTTP_PROXY = "https://127.0.0.1"; + const agent = getProxyAgent(); + expect(agent).toBeInstanceOf(ProxyAgent); + }); + + it("should return a ProxyAgent for the httpsProxy environment variable", () => { + process.env.HTTPS_PROXY = "https://127.0.0.1"; + const agent = getProxyAgent(); + expect(agent).toBeInstanceOf(ProxyAgent); + }); + + it("should return undefined if no proxy environment variables are set", () => { + const agent = getProxyAgent(); + expect(agent).toBeUndefined(); }); it("happy path with GITHUB_TOKEN", () => { @@ -175,11 +230,12 @@ describe("Smoke test", () => { title: "My test issue", }); - expect(data).toStrictEqual({ ok: true }); + // TODO: need a follow up issue to clean this up + expect(JSON.stringify(data)).toStrictEqual(JSON.stringify({ ok: true })); }); it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( - "Uses https-proxy-agent with %s env var", + "Uses ProxyAgent with %s env var", async (https_proxy_env) => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; @@ -209,52 +265,46 @@ describe("Smoke test", () => { title: "My test issue", }); - expect(HttpsProxyAgent).toHaveBeenCalled(); - const [call] = fetchSandbox.calls(); expect(call[0]).toEqual( "https://api.github.com/repos/octocat/hello-world/issues", ); - expect((call[1] as RequestOptions).agent).toBeInstanceOf(HttpsProxyAgent); }, ); + describe("customFetch", () => { + afterAll(() => { + delete process.env.HTTPS_PROXY; + jest.clearAllMocks(); + }); - it("Uses the explicitly provided request.agent value if it's provided", async () => { - process.env.GITHUB_TOKEN = "secret123"; - process.env.GITHUB_ACTION = "test"; - process.env.HTTPS_PROXY = "https://127.0.0.1"; - - const fetchSandbox = fetchMock.sandbox(); - const mock = fetchSandbox.post( - "path:/repos/octocat/hello-world/issues", - { id: 1 }, - { - body: { - title: "My test issue", - }, - }, - ); + it("should call undiciFetch with the correct dispatcher", async () => { + process.env.HTTPS_PROXY = "https://127.0.0.1"; + const expectedAgent = new ProxyAgent("https://127.0.0.1"); - expect(Octokit).toBeInstanceOf(Function); - const octokit = new Octokit({ - auth: "secret123", - request: { - fetch: mock, - agent: null, - }, - }); - await octokit.request("POST /repos/{owner}/{repo}/issues", { - owner: "octocat", - repo: "hello-world", - title: "My test issue", - }); + jest.mock("../src", () => { + const actualModule = jest.requireActual("../src"); + return { + ...actualModule, + getProxyAgent: jest.fn(() => expectedAgent), + }; + }); + expect(JSON.stringify(getProxyAgent())).toBe( + JSON.stringify(expectedAgent), + ); - expect(HttpsProxyAgent).toHaveBeenCalled(); + // mock undici.fetch to extract the `dispatcher` option passed in. + // this allows us to verify that `customFetch` correctly sets + // the dispatcher to `expectedAgent` when HTTPS_PROXY is set. + let dispatcher: any; + (undici.fetch as jest.Mock).mockImplementation( + (_url: string, options: any) => { + dispatcher = options.dispatcher; - const [call] = fetchSandbox.calls(); - expect(call[0]).toEqual( - "https://api.github.com/repos/octocat/hello-world/issues", - ); - expect((call[1] as RequestOptions).agent).toBeNull(); + return Promise.resolve(new Response()); + }, + ); + await customFetch("http://api.github.com", {}); + expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(expectedAgent)); + }); }); });