Skip to content

Commit

Permalink
Add skipQuestions flag (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelalmeidatk authored Jul 27, 2020
1 parent d61b1d4 commit 2997ce9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 43 deletions.
28 changes: 21 additions & 7 deletions bin/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ args.option('pre', 'Mark the release as prerelease')
.option('publish', 'Instead of creating a draft, publish the release')
.option(['H', 'hook'], 'Specify a custom file to pipe releases through')
.option(['t', 'previous-tag'], 'Specify previous release', '')
.option(['u', 'show-url'], 'Show the release URL instead of opening it in the browser');
.option(['u', 'show-url'], 'Show the release URL instead of opening it in the browser')
.option(['s', 'skip-questions'], 'Skip the questions and create a simple list without the headings');

const flags = args.parse(process.argv);

Expand Down Expand Up @@ -201,6 +202,19 @@ const orderCommits = async (commits, tags, exists) => {
continue;
}

// If we are skipping the questions, don't let them be included
// in the list
if (flags.skipQuestions) {
predefined[commit.hash] = {
// The type doesn't matter since it is not included in the
// final changelog
type: 'patch',
message
};

continue;
}

questions.push({
name: commit.hash,
message,
Expand All @@ -218,7 +232,7 @@ const orderCommits = async (commits, tags, exists) => {
// By default, nothing is there yet
let answers = {};

if (choices) {
if (choices && questions.length > 0) {
console.log(
`${chalk.green('!')} Please enter the type of change for each commit:\n`
);
Expand All @@ -238,18 +252,18 @@ const orderCommits = async (commits, tags, exists) => {
message
};
}
}

// Update the spinner status
if (choices) {
console.log('');
// Update the spinner status
if (choices) {
console.log('');
}
}

createSpinner('Generating the changelog');

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

let {credits, changelog} = changes;

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

module.exports = async (types, commits, changeTypes, filteringWithHook, showURL) => {
const getChangesListText = async (changes, commits, changeTypes, filteringWithHook, showURL, credits) => {
// This is the bullet list with each change of the type
let text = '';

// Find last change, in order to be able
// to add a newline after it
const lastChange = changes[changes.length - 1];

for (const change of changes) {
const changeDetails = await pickCommit(
change,
commits.all,
changeTypes,
// Do not escape HTML from commit title
// if a custom hook is being used
!filteringWithHook,
showURL
);

if (changeDetails.text) {
text += changeDetails.text;
}

if (changeDetails.credits && changeDetails.credits.length > 0) {
changeDetails.credits.forEach(item => {
// Don't add bots to the credits
if (item.includes('[bot]')) {
return;
}

credits.add(item);
});
}

if (change === lastChange) {
text += '\n';
}
}

return text;
};

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

Expand All @@ -31,45 +73,21 @@ module.exports = async (types, commits, changeTypes, filteringWithHook, showURL)
continue;
}

const changesListText = await getChangesListText(changes, commits, changeTypes, filteringWithHook, showURL, credits);

// If the user skipped the questions, we will render only the changes list without
// the heading
if (skippedQuestions) {
text += changesListText;
continue;
}

const typeInfo = changeTypes.filter(item => item.handle === type)[0];

// Add heading
text += `### ${typeInfo.pluralName} \n\n`;

// Find last change, in order to be able
// to add a newline after it
const lastChange = changes[changes.length - 1];

for (const change of changes) {
const changeDetails = await pickCommit(
change,
commits.all,
changeTypes,
// Do not escape HTML from commit title
// if a custom hook is being used
!filteringWithHook,
showURL
);

if (changeDetails.text) {
text += changeDetails.text;
}

if (changeDetails.credits && changeDetails.credits.length > 0) {
changeDetails.credits.forEach(item => {
// Don't add bots to the credits
if (item.includes('[bot]')) {
return;
}

credits.add(item);
});
}

if (change === lastChange) {
text += '\n';
}
}
// Add the changes list
text += changesListText;
}

const username = await getAuthor(commits.latest);
Expand Down

0 comments on commit 2997ce9

Please sign in to comment.