Skip to content

Commit

Permalink
Fixes github.proxy not working (#863) (#893)
Browse files Browse the repository at this point in the history
Based on a recent change in Octokits docs[1], in order for it to use a
configured proxy you must pass another request.agent into the Octokit
constructor. This change adds the `proxy-agent` lib as suggested by
Octokits docs.

Note that with this implmentation, the `http_proxy` or `https_proxy`
environment variables alone will NOT work. Instead one must explicitly
set the value in the `github.proxy` option passed to release-it. This is
to stay inline with current behavior[2].

[1] octokit/octokit.js@2090c85
[2] https://github.com/release-it/release-it/blob/14.14.2/docs/github-releases.md#proxy
  • Loading branch information
dgcofer committed Apr 14, 2022
1 parent d725bab commit 1fe1afa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/plugin/github/GitHub.js
Expand Up @@ -11,6 +11,7 @@ const pkg = require('../../../package.json');
const { format, parseVersion, e } = require('../../util');
const Release = require('../GitRelease');
const prompts = require('./prompts');
const ProxyAgent = require('proxy-agent');

const docs = 'https://git.io/release-it-github';

Expand Down Expand Up @@ -167,7 +168,7 @@ class GitHub extends Release {
};

if (proxy) {
options.proxy = proxy;
options.request.agent = new ProxyAgent(proxy);
}

const client = new Octokit(options);
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -77,6 +77,7 @@
"os-name": "4.0.1",
"parse-json": "5.2.0",
"promise.allsettled": "1.0.5",
"proxy-agent": "5.0.0",
"semver": "7.3.5",
"shelljs": "0.8.5",
"update-notifier": "5.1.0",
Expand Down
30 changes: 30 additions & 0 deletions test/github.js
Expand Up @@ -407,3 +407,33 @@ test('should generate GitHub web release url for enterprise host', async t => {
);
exec.restore();
});

test('should generate Github web release when proxy is set', async t => {
const options = {
git,
github: {
pushRepo: 'git://custom.example.org:user/repo',
release: true,
web: true,
host: 'custom.example.org',
releaseName: 'The Launch',
releaseNotes: 'echo It happened',
proxy: 'http://proxy.example.org:8181'
}
};

const github = factory(GitHub, { options });
const exec = sinon.stub(github.shell, 'exec').callThrough();
exec.withArgs('git describe --tags --match=* --abbrev=0').resolves('2.0.1');

await runTasks(github);

const { isReleased, releaseUrl } = github.getContext();
t.true(isReleased);
t.is(
releaseUrl,
'https://custom.example.org/user/repo/releases/new?tag=2.0.2&title=The+Launch&body=It+happened&prerelease=false'
);
t.is(github.options.proxy, 'http://proxy.example.org:8181');
exec.restore();
});

0 comments on commit 1fe1afa

Please sign in to comment.