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

feat: add support for breaking changes #34

Merged
merged 11 commits into from
Dec 17, 2017
Merged

feat: add support for breaking changes #34

merged 11 commits into from
Dec 17, 2017

Conversation

JasonCust
Copy link
Contributor

@JasonCust JasonCust commented Dec 15, 2017

Basing this PR off of feedback for a previous PR #21 with the modification that it would use a more generic and extensible flag option in the commit subject.

Should resolve request #20

@JasonCust JasonCust changed the title feat: add support for breaking changes (#12) feat: add support for breaking changes Dec 15, 2017
@JasonCust JasonCust mentioned this pull request Dec 15, 2017
@robinjoseph08 robinjoseph08 self-assigned this Dec 15, 2017
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.

Thanks @JasonCust for carrying the previous PR! I left a few comments and suggestions, but if you have any questions, feel free to ask!

lib/git.js Outdated
@@ -4,7 +4,7 @@ var Bluebird = require('bluebird');
var CP = Bluebird.promisifyAll(require('child_process'));

var SEPARATOR = '===END===';
var COMMIT_PATTERN = /^(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)$/;
var COMMIT_PATTERN = /^(\w*)(?:\(([^)]*?)\)|):\s*(.*?(?:\[([^\]]+?)\]|))$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a \s* right before the $ at the end? That way, it will also parse the flags correctly even if there's a trailing space on the commit message.

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 can make this even a bit more flexible by allowing the flags to occur anywhere in the subject line.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be better to enforce it only at the end. I'd rather it be well-defined on when it'll be picked up as opposed to unintentionally being picked up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

lib/git.js Outdated
commit.subject = parsed[3];

if (parsed[4]) {
parsed[4].toLowerCase().split(/\s*,\s*/).forEach(function (flag) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a .trim() right after the .toLowerCase() so account for [ breaking ]?

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'll move inside the forEach to apply the trim to every flag.

lib/git.js Outdated
if (parsed[4]) {
parsed[4].toLowerCase().split(/\s*,\s*/).forEach(function (flag) {
switch (flag) {
case 'breaking': commit.type = flag;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it doesn't matter here too much since it's just one case and it's a one-liner, but can you format it like so:

switch (flag) {
  case 'breaking':
    commit.type = flag;
    break;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

test/git.test.js Outdated
Expect(commits[0]).to.have.property('type');
Expect(commits[0]).to.have.property('category');
Expect(commits[0]).to.have.property('subject');

Expect(commits[5].type).to.eql('breaking');
Copy link
Contributor

Choose a reason for hiding this comment

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

As opposed to including this check on an existing test, can you add an explicit test for the breaking change logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

lib/writer.js Outdated
@@ -6,6 +6,7 @@ var DEFAULT_TYPE = 'other';
var PR_REGEX = new RegExp(/#[1-9][\d]*/g);
var TYPES = {
build: 'Build System / Dependencies',
breaking: 'Breaking Changes',
Copy link
Contributor

Choose a reason for hiding this comment

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

It goes the alphabetical sorting of the others, but I think that breaking changes should probably be at the top of the changelog so that they are more highlighted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

README.md Outdated
@@ -40,6 +40,10 @@ Where `type` is one of the following:
* `style`
* `test`

Where `flags` is one or more of the following (comma separated):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Change it to:

Where `flags` is an optional comma-separated list of one or more of the following (must be surrounded in square brackets):

to make it clear that they're optional and that they need to be surrounded by []s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -22,7 +22,7 @@ $ npm i generate-changelog -g # install it globally
To use this module, your commit messages have to be in this format:

```
type(category): description
type(category): description [flags]
```

Where `type` is one of the following:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're also adding breaking as a type, can you add it to this list as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@JasonCust
Copy link
Contributor Author

Changes should be all set to go.

parsed[4].toLowerCase().split(',').forEach(function (flag) {
flag = flag.trim();

switch (flag) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on just making this flag.trim() instead of reassigning flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The trimmed version needs to be captured either via reassignment or creating a new variable since it used in more than one place (line 77 assigns the value to type in the case of a breaking flag). As far as reassignment goes, in this case I don't see as an issue in the same way reassigning a function parameter for a module API would be for two reasons:

  1. This is essentially a pipeline that is parsing and formatting the flags prior to processing the logic for each flag. I could refactor the trim to occur in a map prior to the switch but I didn't see the need to loop the split flag array twice at this time.
  2. Since flag is a primitive value, reassigning it does not have any side effects (as modifying an object property would).

Copy link
Contributor Author

@JasonCust JasonCust Dec 17, 2017

Choose a reason for hiding this comment

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

The trimmed version needs to be captured either via reassignment or creating a new variable since it used in more than one place (line 77 assigns the value to type in the case of a breaking flag). As far as reassignment goes, in this case I don't see it as an issue in the same manner as reassigning a function parameter for a module API would be for two reasons:

  1. This is essentially a pipeline that is parsing and formatting the flags prior to processing the logic for each flag. I could refactor the trim to occur in a map prior to the switch but I didn't see the need to loop the split flag array twice at this time.
  2. Since flag is a primitive value, reassigning it does not have any side effects (as modifying an object property would).

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.

Last 2 things and it'll be ready to be merged!

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! Thanks again for the contribution! I'll let you know when a new version has been published.

@robinjoseph08 robinjoseph08 merged commit d697b27 into lob:master Dec 17, 2017
@robinjoseph08
Copy link
Contributor

Version v1.7.0 has been published which includes this change. Thanks again for your help!

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.

2 participants