diff --git a/README.md b/README.md index 1b75c40d..05c44102 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ If you have actions that trigger on newly created releases, please use a generat |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------| | `githubUrl` | The GitHub Enterprise endpoint. | `GH_URL` or `GITHUB_URL` environment variable. | | `githubApiPathPrefix` | The GitHub Enterprise API prefix. | `GH_PREFIX` or `GITHUB_PREFIX` environment variable. | -| `proxy` | The proxy to use to access the GitHub API. See [proxy](#proxy). | `HTTP_PROXY` environment variable. | +| `proxy` | The proxy to use to access the GitHub API. Set to `false` to disable usage of proxy. See [proxy](#proxy). | `HTTP_PROXY` environment variable. | | `assets` | An array of files to upload to the release. See [assets](#assets). | - | | `successComment` | The comment to add to each issue and pull request resolved by the release. Set to `false` to disable commenting on issues and pull requests. See [successComment](#successcomment). | `:tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nThe release is available on [GitHub release]()` | | `failComment` | The content of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. See [failComment](#failcomment). | Friendly message with links to **semantic-release** documentation and support, with the list of errors that caused the release to fail. | @@ -86,7 +86,7 @@ If you have actions that trigger on newly created releases, please use a generat #### proxy -Can be a the proxy URL or and `Object` with the following properties: +Can be `false`, a proxy URL or an `Object` with the following properties: | Property | Description | Default | |---------------|----------------------------------------------------------------|--------------------------------------| diff --git a/lib/resolve-config.js b/lib/resolve-config.js index c4635814..91b85a84 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -19,7 +19,7 @@ module.exports = ( githubToken: env.GH_TOKEN || env.GITHUB_TOKEN, githubUrl: githubUrl || env.GITHUB_API_URL || env.GH_URL || env.GITHUB_URL, githubApiPathPrefix: githubApiPathPrefix || env.GH_PREFIX || env.GITHUB_PREFIX || '', - proxy: proxy || env.HTTP_PROXY, + proxy: isNil(proxy) ? env.http_proxy || env.HTTP_PROXY || false : proxy, assets: assets ? castArray(assets) : assets, successComment, failTitle: isNil(failTitle) ? 'The automated release is failing 🚨' : failTitle, diff --git a/lib/verify.js b/lib/verify.js index 465e1665..e9ee6bb7 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -14,8 +14,9 @@ const isArrayOf = (validator) => (array) => isArray(array) && array.every((value const canBeDisabled = (validator) => (value) => value === false || validator(value); const VALIDATORS = { - proxy: (proxy) => - isNonEmptyString(proxy) || (isPlainObject(proxy) && isNonEmptyString(proxy.host) && isNumber(proxy.port)), + proxy: canBeDisabled( + (proxy) => isNonEmptyString(proxy) || (isPlainObject(proxy) && isNonEmptyString(proxy.host) && isNumber(proxy.port)) + ), assets: isArrayOf( (asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path)) ), diff --git a/test/get-client.test.js b/test/get-client.test.js index c34a6beb..16fa09c8 100644 --- a/test/get-client.test.js +++ b/test/get-client.test.js @@ -88,6 +88,33 @@ test.serial('Use a https proxy', async (t) => { await promisify(server.destroy).bind(server)(); }); +test.serial('Do not use a proxy if set to false', async (t) => { + const server = http.createServer(); + await promisify(server.listen).bind(server)(); + const serverPort = server.address().port; + serverDestroy(server); + + const serverHandler = spy((request, response) => { + response.end(); + }); + server.on('request', serverHandler); + + const github = getClient({ + githubToken: 'github_token', + githubUrl: `http://localhost:${serverPort}`, + githubApiPathPrefix: '', + proxy: false, + }); + + await github.repos.get({repo: 'repo', owner: 'owner'}); + + t.is(serverHandler.args[0][0].headers.accept, 'application/vnd.github.v3+json'); + t.falsy(serverHandler.args[0][0].headers.via); + t.falsy(serverHandler.args[0][0].headers['x-forwarded-for']); + + await promisify(server.destroy).bind(server)(); +}); + test('Use the global throttler for all endpoints', async (t) => { const rate = 150; diff --git a/test/verify.test.js b/test/verify.test.js index 9b62accf..f428e741 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -207,6 +207,25 @@ test.serial('Verify "proxy" is an object with "host" and "port" properties', asy t.true(github.isDone()); }); +test.serial('Verify "proxy" is a Boolean set to false', async (t) => { + const owner = 'test_user'; + const repo = 'test_repo'; + const env = {GH_TOKEN: 'github_token'}; + const proxy = false; + const github = authenticate(env) + .get(`/repos/${owner}/${repo}`) + .reply(200, {permissions: {push: true}}); + + await t.notThrowsAsync( + verify( + {proxy}, + {env, options: {repositoryUrl: `git@othertesturl.com:${owner}/${repo}.git`}, logger: t.context.logger} + ) + ); + + t.true(github.isDone()); +}); + test.serial('Verify "assets" is a String', async (t) => { const owner = 'test_user'; const repo = 'test_repo';