Skip to content

Commit

Permalink
Move release url get/set to github client
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Dec 19, 2018
1 parent 7f68a3a commit 50087b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 10 additions & 1 deletion lib/github-client.js
Expand Up @@ -91,6 +91,7 @@ const release = ({ version, tagName, repo, changelog = '', github }) => {
response.data.name
}")`
);
config.setOption('githubReleaseUrl', response.data.html_url);
return response.data;
} catch (err) {
const msg = parseErrorMessage(err);
Expand Down Expand Up @@ -171,7 +172,15 @@ const uploadAssets = ({ release, repo, github }) => {
});
};

const getReleaseUrlFallback = () => {
const tag = format(config.getOption('git.tagName'));
return format(`https://\${repo.host}/\${repo.repository}/releases/tag/${tag}`);
};

const getReleaseUrl = () => config.getOption('githubReleaseUrl') || getReleaseUrlFallback();

module.exports = {
release,
uploadAssets
uploadAssets,
getReleaseUrl
};
12 changes: 1 addition & 11 deletions lib/tasks.js
Expand Up @@ -25,11 +25,6 @@ const {
InvalidVersionError
} = require('./errors');

const getGithubHtmlUrl = releaseInfo => {
// releaseInfo is no initialized during a dry-run, so we need a fallback
return releaseInfo && releaseInfo.html_url ? releaseInfo.html_url : config.options.repo.remote;
}

const validateRepoState = async options => {
const { github, git, dist } = options;
const { requireCleanWorkingDir, requireUpstream } = git;
Expand Down Expand Up @@ -181,14 +176,12 @@ module.exports = async options => {
const uploadAssets = release => githubClient.uploadAssets({ release, repo, github });
const otpPrompt = task => prompt(true, 'src', 'otp', task);
const publish = () => npmPublish(npm, options.name, isInteractive && otpPrompt);
let githubHtmlUrl = null;

if (!isInteractive) {
await spinner(git.commit, commit, 'Git commit');
await spinner(git.tag, tag, 'Git tag');
await spinner(git.push, push, 'Git push');
const releaseInfo = await spinner(github.release, release, 'GitHub release');
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
await spinner(github.assets && releaseInfo, () => uploadAssets(releaseInfo), 'GitHub upload assets');
if (!npm.private) {
await spinner(npm.publish, publish, 'npm publish');
Expand All @@ -199,7 +192,6 @@ module.exports = async options => {
await prompt(git.push, 'src', 'push', push);
await prompt(github.release, 'src', 'release', async () => {
const releaseInfo = await release();
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
return github.assets && releaseInfo && (await uploadAssets(releaseInfo));
});
if (!npm.private) {
Expand Down Expand Up @@ -253,7 +245,6 @@ module.exports = async options => {
await spinner(shouldTag, tag, 'Git tag');
await spinner(git.push, push, 'Git push');
const releaseInfo = await spinner(github.release, release, 'GitHub release');
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
await spinner(github.assets && releaseInfo, () => uploadAssets(releaseInfo), 'GitHub upload assets');
await spinner(npm.publish, publish, 'npm publish');
} else {
Expand All @@ -263,7 +254,6 @@ module.exports = async options => {
await prompt(git.push, 'dist', 'push', push);
await prompt(github.release, 'dist', 'release', async () => {
const releaseInfo = await release();
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
return github.assets && releaseInfo && (await uploadAssets(releaseInfo));
});
await prompt(npm.publish, 'dist', 'publish', publish);
Expand All @@ -276,7 +266,7 @@ module.exports = async options => {
}

if (github.release) {
log(`πŸ”— ${githubHtmlUrl}`);
log(`πŸ”— ${githubClient.getReleaseUrl()}`);
}
if (npm.publish) {
log(`πŸ”— ${getPackageUrl()}`);
Expand Down

0 comments on commit 50087b9

Please sign in to comment.