Skip to content

Commit

Permalink
fix: ensure the link pointing to the new release is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwinter committed Aug 26, 2021
1 parent e8261e0 commit 71a5c77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
38 changes: 25 additions & 13 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import meow from 'meow';
import updateNotifier from 'update-notifier';
import readJson from 'read-package-json';

import client from './client.js';
import createClient from './client.js';
import * as readysteady from './index.js';

readJson('./package.json', (error, data) => {
Expand Down Expand Up @@ -46,44 +46,56 @@ const {owner, repo, tag, force, files} = cli.flags;

(async () => {
let spinner = null;
spinner = createSpinner(`Check if tag is available: ${tag}`);
spinner = createSpinner('Checking for GitHub authentication token');

try {
const client = createClient();

spinner.succeed('GitHub authentication token detected');

spinner = createSpinner(`Checking that tag is available: ${tag}`);

if (!await readysteady.isTagAvailable({client, owner, repo, tag})) {
throw new Error(`Tag is not available: ${tag}`);
throw new Error(`Tag is not available and has already been used: ${tag}`);
}

spinner.succeed(`Tag available: ${tag}`);
spinner.succeed(`Tag is available for a draft release: ${tag}`);

const releaseName = tag.slice(1);

spinner = createSpinner(`Check if draft release is available: ${releaseName}`);
spinner = createSpinner(`Checking if draft release is available: ${releaseName}`);

const existingDraftRelease = await readysteady.getExistingDraftRelease({client, owner, repo, releaseName});

if (existingDraftRelease) {
spinner.info(`Draft release already exists: ${releaseName}`);
spinner.info(`A draft release already exists: ${releaseName}`);

if (force) {
spinner.info('--force detected, deleting existing draft release');
spinner.info('--force flag detected, deleting the existing draft release');
await readysteady.deleteDraftRelease({client, owner, repo, release: existingDraftRelease});
spinner.succeed('Existing draft release deleted');
} else {
throw new Error('existing draft release found, and force not used');
throw new Error('An existing draft release was found. Use --force to delete and replace with a new draft release');
}
}

spinner = createSpinner(`Create draft release: ${releaseName}`);
spinner = createSpinner(`Creating a new draft release: ${releaseName}`);

const newDraftRelease = await readysteady.createDraftRelease({client, owner, repo, tag, releaseName});

spinner.succeed(`Draft release created: ${releaseName} ${newDraftRelease.url}`);
spinner.succeed(`A new draft release was created: ${releaseName}`);

spinner = createSpinner('Uploading files');
if (files.length) {
spinner = createSpinner('Uploading files to the draft release');

await readysteady.uploadFilesToDraftRelease({client, fs, owner, repo, release: newDraftRelease, files});

spinner.succeed('Files uploaded to draft release');
}

await readysteady.uploadFilesToDraftRelease({client, fs, owner, repo, release: newDraftRelease, files});
console.log('\nDraft release successfully created 🎉');

spinner.succeed('Files uploaded to draft release');
console.log(`You can edit the release here: ${newDraftRelease.data.html_url.replace('/tag/', '/edit/')}\n`);
} catch (error) {
spinner.fail(error.message);
process.exit(1);
Expand Down
14 changes: 9 additions & 5 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import {Octokit} from '@octokit/core';
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods';
import {paginateRest} from '@octokit/plugin-paginate-rest';

const MyOctokit = Octokit.plugin(restEndpointMethods, paginateRest);
const createClient = () => {
const MyOctokit = Octokit.plugin(restEndpointMethods, paginateRest);

if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN environment variable not detected');
}
if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN environment variable not detected');
}

export default new MyOctokit({auth: process.env.GITHUB_TOKEN});
return new MyOctokit({auth: process.env.GITHUB_TOKEN});
};

export default createClient;

0 comments on commit 71a5c77

Please sign in to comment.