Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass node-fetch as options.request.fetch to the Octokit constructor #225

Closed
wants to merge 3 commits into from

Conversation

nickfloyd
Copy link
Contributor

After speaking with @gr2m we decided to pass in node-fetch (as an option) to the Octokit constructor now that request.js has changed.

This should ensure that the action will work as is without requiring a node bump and or changes on the consumer side (avoiding breaking changes)

Relates to #221


Behavior

Before the change?

  • Prior to this change a breaking change was going to be introduced as part of this effort because of the change around support for Node's HTTP agent.

After the change?

  • There should no longer be a need for a breaking change to be introduced here and theoretically, this should still be able to "support" node v16. The end goal would be to remove this once Actions moves to Node v18 as their runtime.

@nickfloyd nickfloyd added the Type: Feature New feature or request label Jul 12, 2023
@nickfloyd nickfloyd changed the base branch from main to renovate/major-octokit-monorepo July 12, 2023 19:30
@wolfy1339
Copy link
Member

Since the other Octokit modules that power this one dropped support for Node 16, it is going to be harder to keep support

@nickfloyd
Copy link
Contributor Author

Since the other Octokit modules that power this one dropped support for Node 16, it is going to be harder to keep support

Agreed, and I don't like having a special case; can you think of another way to handle this?

Currently, these are all kinda blocking each other:

I'm trying to find a clean path to move forward, but I keep walking into the agent support / node v16 walls. I'd love to hear thoughts or clarity from all that have been involved so far (@gr2m, @wolfy1339, @kfcampbell, @oscard0m) - I might be overthinking this or simply in need of a better perspective. I am sure we can come up with a decent path to get these last 3 libraries landed.

Let me know y'alls thoughts.

@wolfy1339
Copy link
Member

Undici supports Node 16, no problem.
We could use that so that every platform has a similar experience

They implement an AgentProxy() that we can use to replace https-proxy-agent.
It seems a pretty easy replacement

In @octokit/action these are the changes I would propose:

diff --git a/src/index.ts b/src/index.ts
index 0998398..f293763 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,
@@ -17,16 +17,22 @@ const DEFAULTS = {
 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;
 }
+const customFetch = async function(url: string, opts: any) {
+  return await undiciFetch(url, {
+    dispatcher: getProxyAgent(),
+    ...opts
+  });
+};
 
 export const Octokit = Core.plugin(
   paginateRest,
@@ -36,7 +42,7 @@ export const Octokit = Core.plugin(
     ...DEFAULTS,
     ...options,
     request: {
-      agent: getProxyAgent(),
+      fetch: customFetch,
       ...options.request,
     },
   };

@gr2m
Copy link
Contributor

gr2m commented Jul 12, 2023

I like @wolfy1339's approach 👍🏼

@nickfloyd
Copy link
Contributor Author

Implemented here: octokit/action.js#513

@renovate renovate bot force-pushed the renovate/major-octokit-monorepo branch from bd9eea8 to 2ca7eeb Compare July 17, 2023 04:25
Base automatically changed from renovate/major-octokit-monorepo to main July 18, 2023 21:36
@kfcampbell
Copy link
Member

Closing this as the fetch changes were handled in #221.

@kfcampbell kfcampbell closed this Jul 19, 2023
@kfcampbell kfcampbell deleted the pass-node-fetch branch July 19, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants