-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support the no_proxy environment variable
Closes #563 BREAKING CHANGE: The `no_proxy` and `NO_PROXY` environment variables are now respected when obtaining proxy configuration from the environment, bypassing the proxy when they match the GitHub host. This does not apply when [`proxy`](https://github.com/semantic-release/github#proxy) is explicitly provided in the plugin configuration.
- Loading branch information
1 parent
5d1f65e
commit 1603e2f
Showing
3 changed files
with
88 additions
and
18 deletions.
There are no files selected for viewing
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,24 @@ | ||
module.exports = (githubUrl, env) => { | ||
githubUrl ||= 'https://github.com'; | ||
const proxy = env.http_proxy || env.HTTP_PROXY || false; | ||
const noProxy = env.no_proxy || env.NO_PROXY; | ||
|
||
if (proxy && noProxy) { | ||
const {hostname} = new URL(githubUrl); | ||
for (let noProxyHost of noProxy.split(',')) { | ||
if (noProxyHost === '*') { | ||
return false; | ||
} | ||
|
||
if (noProxyHost.startsWith('.')) { | ||
noProxyHost = noProxyHost.slice(1); | ||
} | ||
|
||
if (hostname === noProxyHost || hostname.endsWith('.' + noProxyHost)) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return proxy; | ||
}; |
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,41 @@ | ||
const test = require('ava'); | ||
const resolveProxy = require('../lib/resolve-proxy'); | ||
|
||
test('Resolve proxy with no proxy configuration', (t) => { | ||
t.is(resolveProxy(undefined, {}), false); | ||
}); | ||
|
||
test('Resolve proxy with no exclusions', (t) => { | ||
t.is(resolveProxy(undefined, {http_proxy: 'proxy.example.com'}), 'proxy.example.com'); | ||
}); | ||
|
||
test('Resolve proxy with no matching exclusion', (t) => { | ||
t.is( | ||
resolveProxy(undefined, {http_proxy: 'proxy.example.com', no_proxy: 'notgithub.com,.example.org,example.net'}), | ||
'proxy.example.com' | ||
); | ||
}); | ||
|
||
test('Resolve proxy with matching exclusion', (t) => { | ||
t.is(resolveProxy(undefined, {http_proxy: 'proxy.example.com', no_proxy: 'github.com'}), false); | ||
}); | ||
|
||
test('Resolve proxy with matching exclusion (leading .)', (t) => { | ||
t.is(resolveProxy(undefined, {http_proxy: 'proxy.example.com', no_proxy: '.github.com'}), false); | ||
}); | ||
|
||
test('Resolve proxy with global exclusion', (t) => { | ||
t.is(resolveProxy(undefined, {http_proxy: 'proxy.example.com', no_proxy: '*'}), false); | ||
}); | ||
|
||
test('Resolve proxy with matching GitHub Enterprise exclusion', (t) => { | ||
t.is(resolveProxy('https://github.example.com', {http_proxy: 'proxy.example.com', no_proxy: 'example.com'}), false); | ||
}); | ||
|
||
test('Resolve proxy with uppercase environment variables', (t) => { | ||
t.is(resolveProxy(undefined, {HTTP_PROXY: 'proxy.example.com', NO_PROXY: 'github.com'}), false); | ||
t.is( | ||
resolveProxy(undefined, {HTTP_PROXY: 'proxy.example.com', NO_PROXY: 'subdomain.github.com'}), | ||
'proxy.example.com' | ||
); | ||
}); |