Skip to content

Commit bea917f

Browse files
SwiftworkErik Hughes
and
Erik Hughes
authoredApr 5, 2021
fix: allow proxy to be false and fallback an empty string (#356)
Co-authored-by: Erik Hughes <erik.hughes@seb.se>
1 parent 8cb77a1 commit bea917f

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ If you have actions that trigger on newly created releases, please use a generat
7474
|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
7575
| `githubUrl` | The GitHub Enterprise endpoint. | `GH_URL` or `GITHUB_URL` environment variable. |
7676
| `githubApiPathPrefix` | The GitHub Enterprise API prefix. | `GH_PREFIX` or `GITHUB_PREFIX` environment variable. |
77-
| `proxy` | The proxy to use to access the GitHub API. See [proxy](#proxy). | `HTTP_PROXY` environment variable. |
77+
| `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. |
7878
| `assets` | An array of files to upload to the release. See [assets](#assets). | - |
7979
| `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>)` |
8080
| `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
8686

8787
#### proxy
8888

89-
Can be a the proxy URL or and `Object` with the following properties:
89+
Can be `false`, a proxy URL or an `Object` with the following properties:
9090

9191
| Property | Description | Default |
9292
|---------------|----------------------------------------------------------------|--------------------------------------|

‎lib/resolve-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = (
1919
githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
2020
githubUrl: githubUrl || env.GITHUB_API_URL || env.GH_URL || env.GITHUB_URL,
2121
githubApiPathPrefix: githubApiPathPrefix || env.GH_PREFIX || env.GITHUB_PREFIX || '',
22-
proxy: proxy || env.HTTP_PROXY,
22+
proxy: isNil(proxy) ? env.http_proxy || env.HTTP_PROXY || false : proxy,
2323
assets: assets ? castArray(assets) : assets,
2424
successComment,
2525
failTitle: isNil(failTitle) ? 'The automated release is failing 🚨' : failTitle,

‎lib/verify.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const isArrayOf = (validator) => (array) => isArray(array) && array.every((value
1414
const canBeDisabled = (validator) => (value) => value === false || validator(value);
1515

1616
const VALIDATORS = {
17-
proxy: (proxy) =>
18-
isNonEmptyString(proxy) || (isPlainObject(proxy) && isNonEmptyString(proxy.host) && isNumber(proxy.port)),
17+
proxy: canBeDisabled(
18+
(proxy) => isNonEmptyString(proxy) || (isPlainObject(proxy) && isNonEmptyString(proxy.host) && isNumber(proxy.port))
19+
),
1920
assets: isArrayOf(
2021
(asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
2122
),

‎test/get-client.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@ test.serial('Use a https proxy', async (t) => {
8888
await promisify(server.destroy).bind(server)();
8989
});
9090

91+
test.serial('Do not use a proxy if set to false', async (t) => {
92+
const server = http.createServer();
93+
await promisify(server.listen).bind(server)();
94+
const serverPort = server.address().port;
95+
serverDestroy(server);
96+
97+
const serverHandler = spy((request, response) => {
98+
response.end();
99+
});
100+
server.on('request', serverHandler);
101+
102+
const github = getClient({
103+
githubToken: 'github_token',
104+
githubUrl: `http://localhost:${serverPort}`,
105+
githubApiPathPrefix: '',
106+
proxy: false,
107+
});
108+
109+
await github.repos.get({repo: 'repo', owner: 'owner'});
110+
111+
t.is(serverHandler.args[0][0].headers.accept, 'application/vnd.github.v3+json');
112+
t.falsy(serverHandler.args[0][0].headers.via);
113+
t.falsy(serverHandler.args[0][0].headers['x-forwarded-for']);
114+
115+
await promisify(server.destroy).bind(server)();
116+
});
117+
91118
test('Use the global throttler for all endpoints', async (t) => {
92119
const rate = 150;
93120

‎test/verify.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ test.serial('Verify "proxy" is an object with "host" and "port" properties', asy
207207
t.true(github.isDone());
208208
});
209209

210+
test.serial('Verify "proxy" is a Boolean set to false', async (t) => {
211+
const owner = 'test_user';
212+
const repo = 'test_repo';
213+
const env = {GH_TOKEN: 'github_token'};
214+
const proxy = false;
215+
const github = authenticate(env)
216+
.get(`/repos/${owner}/${repo}`)
217+
.reply(200, {permissions: {push: true}});
218+
219+
await t.notThrowsAsync(
220+
verify(
221+
{proxy},
222+
{env, options: {repositoryUrl: `git@othertesturl.com:${owner}/${repo}.git`}, logger: t.context.logger}
223+
)
224+
);
225+
226+
t.true(github.isDone());
227+
});
228+
210229
test.serial('Verify "assets" is a String', async (t) => {
211230
const owner = 'test_user';
212231
const repo = 'test_repo';

0 commit comments

Comments
 (0)
Please sign in to comment.