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(writer): don't print category if empty #16

Merged
merged 1 commit into from
Jun 12, 2017
Merged

fix(writer): don't print category if empty #16

merged 1 commit into from
Jun 12, 2017

Conversation

tvardy
Copy link
Contributor

@tvardy tvardy commented Jun 4, 2017

fixes #6 and #7

Copy link
Contributor

@robinjoseph08 robinjoseph08 left a comment

Choose a reason for hiding this comment

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

A few questions and small fixes! Thanks a ton for helping us with this!

lib/writer.js Outdated
@@ -67,7 +67,7 @@ exports.markdown = function (version, commits, options) {
Object.keys(this.types[type]).forEach(function (category) {
var prefix = '*';
var nested = types[type][category].length > 1;
var categoryHeading = '* **' + category + ':**';
var categoryHeading = prefix + (Boolean(category) ? ' **' + category + ':**' : '');
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to wrap category in Boolean. The empty string will still be false-y and go into the else case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well... your lint setup told me to use Boolean(category) instead of !!category.

But you're right the empty category string is falsy enough ;)

lib/writer.js Outdated
@@ -67,7 +67,7 @@ exports.markdown = function (version, commits, options) {
Object.keys(this.types[type]).forEach(function (category) {
var prefix = '*';
var nested = types[type][category].length > 1;
var categoryHeading = '* **' + category + ':**';
var categoryHeading = prefix + (Boolean(category) ? ' **' + category + ':**' : '');

if (nested) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A problem that arrises is when there are more than one category-less commits. It would then produce the following markdown:

*
  * other changes
  * more changes

which then gets rendered as:

    • other changes
    • more changes

I think in this case, we don't want to nest them. So this if statement should be if (nested && category). That way, even if there are multiple commits with no category, prefix will still just be * and we don't have a separate line for the categoryHeading.

It would probably be good to write a test for this case too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point! I've forgotten that an empty string can be still used as types[type][category]'s key 😆

@@ -144,6 +144,28 @@ describe('writer', function () {
});
});

it('ommits commit category if there was no category defined', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

omits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed! 😉

var hash = '1234567';
var commits = [
{ type: 'feat', category: 'testing', subject: 'did some testing', hash: hash + 'a' },
{ type: 'chore', category: '', subject: 'other changes', hash: hash + 'a' }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you're adding a to the end of the hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No! I just didn't like the fact that two commits would eventually have the same hash...

];

return Writer.markdown(VERSION, commits, {})
.then(function (changelog) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Like in the other PR, can you align this promise chain with the return?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed! 😉

.then(function (line) {
var regex = new RegExp('^\\* other changes \\(1234567a\\)$');

Expect(line).to.match(regex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this regex is just checking that it equals a literal string, you can just use .to.eql instead:

Expect(line).to.eql('* other changes (1234567)');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm now checking both lines with Chai's .equal()

Copy link
Contributor

@robinjoseph08 robinjoseph08 left a comment

Choose a reason for hiding this comment

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

LGTM! I'll cut a new version with both of your PRs in it 👍

@robinjoseph08 robinjoseph08 merged commit 7bdbe7a into lob:master Jun 12, 2017
@robinjoseph08
Copy link
Contributor

Just published v1.2.0! Thanks again!

@tvardy tvardy deleted the allow-no-category branch June 12, 2017 19:55
@tvardy tvardy mentioned this pull request Jun 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Ignore commit messages that do not adhere to the format
2 participants