-
Notifications
You must be signed in to change notification settings - Fork 127
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
Conversation
There was a problem hiding this 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*(.*?(?:\[([^\]]+?)\]|))$/; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 ]
?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Changes should be all set to go. |
parsed[4].toLowerCase().split(',').forEach(function (flag) { | ||
flag = flag.trim(); | ||
|
||
switch (flag) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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:
- 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. - Since
flag
is a primitive value, reassigning it does not have any side effects (as modifying an object property would).
There was a problem hiding this comment.
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:
- 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. - Since
flag
is a primitive value, reassigning it does not have any side effects (as modifying an object property would).
There was a problem hiding this 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!
There was a problem hiding this 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.
Version v1.7.0 has been published which includes this change. Thanks again for your help! |
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