8000 fix: publish a release when env.GITHUB_URL is set to https://github.c… · semantic-release/github@543f40b · GitHub
[go: up one dir, main page]

Skip to content

Commit 543f40b

Browse files
authored
fix: publish a release when env.GITHUB_URL is set to https://github.com (#269)
1 parent 8027e91 commit 543f40b

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ If you have actions that trigger on newly created releases, please use a generat
6464

6565
### Environment variables
6666

67-
| Variable | Description |
68-
| ------------------------------ | --------------------------------------------------------- |
69-
| `GH_TOKEN` or `GITHUB_TOKEN` | **Required.** The token used to authenticate with GitHub. |
70-
| `GH_URL` or `GITHUB_URL` | The GitHub Enterprise endpoint. |
71-
| `GH_PREFIX` or `GITHUB_PREFIX` | The GitHub Enterprise API prefix. |
67+
| Variable | Description |
68+
| -------------------------------------------------- | --------------------------------------------------------- |
69+
| `GH_TOKEN` or `GITHUB_TOKEN` | **Required.** The token used to authenticate with GitHub. |
70+
| `GITHUB_API_URL` or `GH_URL` or `GITHUB_URL` | The GitHub Enterprise endpoint. |
71+
| `GH_PREFIX` or `GITHUB_PREFIX` | The GitHub Enterprise API prefix. |
7272

7373
### Options
7474

lib/resolve-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = (
1616
{env}
1717
) => ({
1818
githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
19-
githubUrl: githubUrl || env.GH_URL || env.GITHUB_URL,
19+
githubUrl: githubUrl || env.GITHUB_API_URL || env.GH_URL || env.GITHUB_URL,
2020
githubApiPathPrefix: githubApiPathPrefix || env.GH_PREFIX || env.GITHUB_PREFIX || '',
2121
proxy: proxy || env.HTTP_PROXY,
2222
assets: assets ? castArray(assets) : assets,

test/helpers/mock-github.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const nock = require('nock');
55
*
66
* @param {Object} [env={}] Environment variables.
77
* @param {String} [githubToken=env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN'] The github token to return in the authentication response.
8-
* @param {String} [githubUrl=env.GH_URL || env.GITHUB_URL || 'https://api.github.com'] The url on which to intercept http requests.
8+
* @param {String} [githubUrl=env.GITHUB_API_URL || env.GH_URL || env.GITHUB_URL || 'https://api.github.com'] The url on which to intercept http requests.
99
* @param {String} [githubApiPathPrefix=env.GH_PREFIX || env.GITHUB_PREFIX || ''] The GitHub Enterprise API prefix.
1010
* @return {Object} A `nock` object ready to respond to a github authentication request.
1111
*/
1212
function authenticate(
1313
env = {},
1414
{
1515
githubToken = env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN',
16-
githubUrl = env.GH_URL || env.GITHUB_URL || 'https://api.github.com',
16+
githubUrl = env.GITHUB_API_URL || env.GH_URL || env.GITHUB_URL || 'https://api.github.com',
1717
githubApiPathPrefix = env.GH_PREFIX || env.GITHUB_PREFIX || '',
1818
} = {}
1919
) {

test/publish.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,45 @@ test.serial('Throw error without retries for 400 error', async (t) => {
393393
t.is(error.status, 400);
394394
t.true(github.isDone());
395395
});
396+
397+
test.serial(
398+
'Publish a release when env.GITHUB_URL is set to https://github.com (Default in GitHub Actions, #268)',
399+
async (t) => {
400+
const owner = 'test_user';
401+
const repo = 'test_repo';
402+
const env = {
403+
GITHUB_TOKEN: 'github_token',
404+
GITHUB_URL: 'https://github.com',
405+
GITHUB_API_URL: 'https://api.github.com',
406+
};
407+
const pluginConfig = {};
408+
const nextRelease = {gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'};
409+
const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`};
410+
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
411+
const releaseId = 1;
412+
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
413+
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
414+
415+
const github = authenticate(env)
416+
.post(`/repos/${owner}/${repo}/releases`, {
417+
tag_name: nextRelease.gitTag,
418+
name: nextRelease.name,
419+
body: nextRelease.notes,
420+
prerelease: false,
421+
})
422+
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
423+
424+
const result = await publish(pluginConfig, {
425+
cwd,
426+
env,
427+
options,
428+
branch: {type: 'release', main: true},
429+
nextRelease,
430+
logger: t.context.logger,
431+
});
432+
433+
t.is(result.url, releaseUrl);
434+
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
435+
t.true(github.isDone());
436+
}
437+
);

0 commit comments

Comments
 (0)
0