Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: publish a release when env.GITHUB_URL is set to https://github.com #269

Merged
merged 5 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/mock-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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.
*/
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',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels a bit odd that we replicate the implementation of env variable parsing here. We basically test our test helper now, instead of the actual implementation. But I don't have a better idea

githubApiPathPrefix = env.GH_PREFIX || env.GITHUB_PREFIX || '',
} = {}
) {
Expand Down
42 changes: 42 additions & 0 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
.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());
}
);