Skip to content
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
34 changes: 22 additions & 12 deletions bin/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,17 @@ const createRelease = async (tag, changelog, exists) => {
// Wait for the GitHub UI to render the release
await sleep(500);

if (showUrl && releaseURL) {
console.log(`\n${chalk.bold('Done!')} ${releaseURL}`);
} else if (releaseURL) {
open(releaseURL);
console.log(`\n${chalk.bold('Done!')} Opening release in browser...`);
if (!showUrl) {
try {
await open(releaseURL);
console.log(`\n${chalk.bold('Done!')} Opened release in browser...`);

return;
// eslint-disable-next-line no-empty
} catch (err) {}
}

console.log(`\n${chalk.bold('Done!')} ${releaseURL}`);
};

const orderCommits = async (commits, tags, exists) => {
Expand Down Expand Up @@ -245,7 +250,7 @@ const orderCommits = async (commits, tags, exists) => {

const results = Object.assign({}, predefined, answers);
const grouped = groupChanges(results, changeTypes);
const changes = await createChangelog(grouped, commits, changeTypes, flags.hook);
const changes = await createChangelog(grouped, commits, changeTypes, flags.hook, flags.showUrl);

let {credits, changelog} = changes;

Expand Down Expand Up @@ -313,7 +318,7 @@ const checkReleaseStatus = async () => {
fail('Your branch needs to be up-to-date with origin.');
}

githubConnection = await connect();
githubConnection = await connect(flags.showUrl);
repoDetails = await getRepo(githubConnection);

createSpinner('Checking if release already exists');
Expand Down Expand Up @@ -363,14 +368,19 @@ const checkReleaseStatus = async () => {
console.log('');

const releaseURL = getReleaseURL(existingRelease);
const prefix = `${chalk.red('Error!')} Release already exists`;

if (!flags.showUrl && releaseURL) {
open(releaseURL);
}
if (!flags.showUrl) {
try {
await open(releaseURL);
console.error(`${prefix}. Opened in browser...`);

const alreadyThere = `Release already exists${flags.showUrl ? `: ${releaseURL}` : '. Opening in browser...'}`;
console.error(`${chalk.red('Error!')} ${alreadyThere}`);
return;
// eslint-disable-next-line no-empty
} catch (err) {}
}

console.error(`${prefix}: ${releaseURL}`);
process.exit(1);
};

Expand Down
5 changes: 3 additions & 2 deletions lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getAuthor = async ({author}) => {
return username;
};

module.exports = async (types, commits, changeTypes, filteringWithHook) => {
module.exports = async (types, commits, changeTypes, filteringWithHook, showURL) => {
let text = '';
const credits = new Set();

Expand Down Expand Up @@ -47,7 +47,8 @@ module.exports = async (types, commits, changeTypes, filteringWithHook) => {
changeTypes,
// Do not escape HTML from commit title
// if a custom hook is being used
!filteringWithHook
!filteringWithHook,
showURL
);

if (changeDetails.text) {
Expand Down
17 changes: 11 additions & 6 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const loadToken = async () => {
return false;
};

const requestToken = async () => {
const requestToken = async showURL => {
let authURL = 'https://github.com/login/oauth/authorize';

const state = randomString({
Expand All @@ -104,9 +104,14 @@ const requestToken = async () => {
authURL += `?${queryString.stringify(params)}`;

try {
if (showURL) {
throw new Error('No browser support');
}

await open(authURL);
} catch (err) {
console.error(`\nCould not open URL in browser. Please open the link: ${authURL}`);
global.spinner.stop();
console.log(`Please click this link to authenticate: ${authURL}`);
}

const token = await tokenAPI(state);
Expand All @@ -115,17 +120,17 @@ const requestToken = async () => {
return token;
};

module.exports = async () => {
module.exports = async showURL => {
let token = await loadToken();

if (!token) {
handleSpinner.create('Opening GitHub authentication page');
handleSpinner.create(showURL ? 'Retrieving authentication link' : 'Opening GitHub authentication page');
await sleep(100);

try {
token = await requestToken();
token = await requestToken(showURL);
} catch (err) {
handleSpinner.fail("Couldn't load token.");
handleSpinner.fail('Could not load token.');
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/pick-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const connect = require('./connect');
const repo = require('./repo');
const definitions = require('./definitions');

const getPullRequest = async number => {
const github = await connect();
const getPullRequest = async (number, showURL) => {
const github = await connect(showURL);
const repoDetails = await repo.getRepo(github);

const response = await github.pullRequests.get({
Expand All @@ -20,11 +20,11 @@ const getPullRequest = async number => {
return response.data;
};

const forPullRequest = async number => {
const forPullRequest = async (number, showURL) => {
let data;

try {
data = await getPullRequest(number);
data = await getPullRequest(number, showURL);
} catch (err) {
return;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ const cleanCommitTitle = (title, changeTypes, doEscapeHTML) => {
};
};

module.exports = async ({hash, message}, all, changeTypes, doEscapeHTML) => {
module.exports = async ({hash, message}, all, changeTypes, doEscapeHTML, showURL) => {
const title = cleanCommitTitle(message, changeTypes, doEscapeHTML);
let credits = [];

Expand All @@ -74,7 +74,7 @@ module.exports = async ({hash, message}, all, changeTypes, doEscapeHTML) => {
const rawHash = hash.split('#')[1];

// Retrieve users that have collaborated on a change
const collaborators = await forPullRequest(rawHash);
const collaborators = await forPullRequest(rawHash, showURL);

if (collaborators) {
credits = credits.concat(collaborators);
Expand Down