Skip to content

Commit

Permalink
fix: allow proxy to be false and fallback an empty string (#356)
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Hughes <erik.hughes@seb.se>
  • Loading branch information
Swiftwork and Erik Hughes committed Apr 5, 2021
1 parent 8cb77a1 commit bea917f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](<github_release_url>)` |
| `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. |
Expand All @@ -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 |
|---------------|----------------------------------------------------------------|--------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion lib/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
),
Expand Down
27 changes: 27 additions & 0 deletions test/get-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
19 changes: 19 additions & 0 deletions test/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit bea917f

Please sign in to comment.