-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: add https proxy env support #329
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56cef03
Add https-proxy-agent package to dependencies
copperwall 5cd5d89
Add autoProxyAgent plugin to respect HTTPS_PROXY env var
copperwall fa3b507
Merge branch 'master' into add-https-proxy-env-support
copperwall ca8d2bc
Set options.request.agent as actions.js default instead of plugin
copperwall f98ca5a
Prefer Octokit constructor options over actions.js defaults
copperwall 547fda2
Update the new unit test name to match the behavior it tests
copperwall File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Octokit } from "@octokit/core"; | ||
import { OctokitOptions } from "@octokit/core/dist-types/types"; | ||
import { HttpsProxyAgent } from "https-proxy-agent"; | ||
|
||
export function autoProxyAgent(octokit: Octokit, options: OctokitOptions) { | ||
const proxy = process.env["HTTPS_PROXY"] || process.env["https_proxy"]; | ||
|
||
if (!proxy) return; | ||
|
||
const agent = new HttpsProxyAgent(proxy); | ||
|
||
octokit.hook.before("request", (options) => { | ||
options.request.agent = agent; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
options
are mutable at this point. I think instead of hooking into the request lifecycle I'd just setoptions.request.agent = agent
directly.I want to do a proper overall with the
@octokit/action
module, and turn it into something like@octokit/app
which provides anoctokit
instance plus some app-specific APIs, instead of just being a customizedOctokit
constructor. That@octokit/action
constructor should accept anenv
option which defaults toprocess.env
, and then sets Octokit options based on that, including setting the request proxy agent. But that will be a bigger projectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response @gr2m, I tried removing the hooks code like you suggested, but I ran into an issue where the fetch wrapper in core.js wasn't receiving the updated request options from the plugin here.
I might be misunderstanding how core.js and plugins work, but it looks like
@octokit/request
is configured with the request options from the default options and those passed when octokit is constructed before any plugins are runRequest options setup: https://github.com/octokit/core.js/blob/master/src/index.ts#L108
Plugins setup: https://github.com/octokit/core.js/blob/master/src/index.ts#L165
I tried setting the agent in the
defaults
static method instead, but that led to some issues in the unit tests where the defaults always the HTTPS_PROXY environment variable value whensrc/index.ts
was imported at the top of the test file, and didn't run again when changing environment variables in the test cases. This probably wouldn't be a big issue when using the module in practice, but I changed the defaults to use the function argument so that it'd read the process.env value when the Octokit class was instantiated in each test case instead of once when the module was imported.How does that sound to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is a much more elegant solution 👏🏼