From 230983bdd809b45d9687b40a28e3276129927cf7 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Thu, 14 May 2020 12:09:01 -0700 Subject: [PATCH 1/5] test: publish a release when env.GITHUB_URL is set to https://github.com --- test/publish.test.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/publish.test.js b/test/publish.test.js index 80dbd3df..59cf02d1 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -393,3 +393,45 @@ test.serial('Throw error without retries for 400 error', async (t) => { t.is(error.status, 400); t.true(github.isDone()); }); + +test.serial( + 'Publish a release when env.GITHUB_URL is set to https://github.com (Default in GitHub Actions, #268)', + async (t) => { + const owner = 'test_user'; + const repo = 'test_repo'; + const env = { + GITHUB_TOKEN: 'github_token', + GITHUB_URL: 'https://github.com', + GITHUB_API_URL: 'https://api.github.com', + }; + const pluginConfig = {}; + const nextRelease = {gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; + const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`}; + const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`; + const releaseId = 1; + const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`; + const uploadUrl = `https://github.com${uploadUri}{?name,label}`; + + const github = authenticate({...env, GITHUB_TOKEN: 'https://api.github.com'}) + .post(`/repos/${owner}/${repo}/releases`, { + tag_name: nextRelease.gitTag, + name: nextRelease.name, + body: nextRelease.notes, + prerelease: false, + }) + .reply(200, {upload_url: uploadUrl, html_url: releaseUrl}); + + const result = await publish(pluginConfig, { + cwd, + env, + options, + branch: {type: 'release', main: true}, + nextRelease, + logger: t.context.logger, + }); + + t.is(result.url, releaseUrl); + t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]); + t.true(github.isDone()); + } +); From 4c7da01d9cbbf96e47cab4199d086a9b1fa9c9e0 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Thu, 14 May 2020 12:25:03 -0700 Subject: [PATCH 2/5] docs(README): `GITHUB_API_URL` environment variable --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 897510eb..1615c05e 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,11 @@ If you have actions that trigger on newly created releases, please use a generat ### Environment variables -| Variable | Description | -| ------------------------------ | --------------------------------------------------------- | -| `GH_TOKEN` or `GITHUB_TOKEN` | **Required.** The token used to authenticate with GitHub. | -| `GH_URL` or `GITHUB_URL` | The GitHub Enterprise endpoint. | -| `GH_PREFIX` or `GITHUB_PREFIX` | The GitHub Enterprise API prefix. | +| Variable | Description | +| -------------------------------------------------- | --------------------------------------------------------- | +| `GH_TOKEN` or `GITHUB_TOKEN` | **Required.** The token used to authenticate with GitHub. | +| `GITHUB_API_URL` or `GH_URL` or `GITHUB_URL` | The GitHub Enterprise endpoint. | +| `GH_PREFIX` or `GITHUB_PREFIX` | The GitHub Enterprise API prefix. | ### Options From 218619b388fbe7cc0148ddff1b282e80bb642cb3 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Thu, 14 May 2020 12:25:21 -0700 Subject: [PATCH 3/5] fix: publish a release when env.GITHUB_URL is set to https://github.com --- lib/resolve-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resolve-config.js b/lib/resolve-config.js index b3a90bf2..22c1eae7 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -16,7 +16,7 @@ module.exports = ( {env} ) => ({ githubToken: env.GH_TOKEN || env.GITHUB_TOKEN, - githubUrl: githubUrl || env.GH_URL || env.GITHUB_URL, + 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, assets: assets ? castArray(assets) : assets, From 140e254691348515e40c91cf47a8909231571e26 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Thu, 14 May 2020 12:26:29 -0700 Subject: [PATCH 4/5] fixup! test: publish a release when env.GITHUB_URL is set to https://github.com --- test/publish.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/publish.test.js b/test/publish.test.js index 59cf02d1..523c622a 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -394,7 +394,7 @@ test.serial('Throw error without retries for 400 error', async (t) => { t.true(github.isDone()); }); -test.serial( +test.serial.only( 'Publish a release when env.GITHUB_URL is set to https://github.com (Default in GitHub Actions, #268)', async (t) => { const owner = 'test_user'; @@ -412,7 +412,7 @@ test.serial( const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`; const uploadUrl = `https://github.com${uploadUri}{?name,label}`; - const github = authenticate({...env, GITHUB_TOKEN: 'https://api.github.com'}) + const github = authenticate({...env, GITHUB_URL: 'https://api.github.com'}) .post(`/repos/${owner}/${repo}/releases`, { tag_name: nextRelease.gitTag, name: nextRelease.name, From 265649f16e3b9ff16eb9744e1c8d2b1e10b1aa09 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Thu, 14 May 2020 12:29:13 -0700 Subject: [PATCH 5/5] test: refactor testing with env.GITHUB_API_URL --- test/helpers/mock-github.js | 4 ++-- test/publish.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/helpers/mock-github.js b/test/helpers/mock-github.js index b14ec700..57ddfb6d 100644 --- a/test/helpers/mock-github.js +++ b/test/helpers/mock-github.js @@ -5,7 +5,7 @@ const nock = require('nock'); * * @param {Object} [env={}] Environment variables. * @param {String} [githubToken=env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN'] The github token to return in the authentication response. - * @param {String} [githubUrl=env.GH_URL || env.GITHUB_URL || 'https://api.github.com'] The url on which to intercept http requests. + * @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. * @param {String} [githubApiPathPrefix=env.GH_PREFIX || env.GITHUB_PREFIX || ''] The GitHub Enterprise API prefix. * @return {Object} A `nock` object ready to respond to a github authentication request. */ @@ -13,7 +13,7 @@ function authenticate( env = {}, { githubToken = env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN', - githubUrl = env.GH_URL || env.GITHUB_URL || 'https://api.github.com', + githubUrl = env.GITHUB_API_URL || env.GH_URL || env.GITHUB_URL || 'https://api.github.com', githubApiPathPrefix = env.GH_PREFIX || env.GITHUB_PREFIX || '', } = {} ) { diff --git a/test/publish.test.js b/test/publish.test.js index 523c622a..2cff370c 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -394,7 +394,7 @@ test.serial('Throw error without retries for 400 error', async (t) => { t.true(github.isDone()); }); -test.serial.only( +test.serial( 'Publish a release when env.GITHUB_URL is set to https://github.com (Default in GitHub Actions, #268)', async (t) => { const owner = 'test_user'; @@ -412,7 +412,7 @@ test.serial.only( const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`; const uploadUrl = `https://github.com${uploadUri}{?name,label}`; - const github = authenticate({...env, GITHUB_URL: 'https://api.github.com'}) + const github = authenticate(env) .post(`/repos/${owner}/${repo}/releases`, { tag_name: nextRelease.gitTag, name: nextRelease.name,