-
-
Notifications
You must be signed in to change notification settings - Fork 1
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: breaking changes are now recognized as meaningful #140
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -40,6 +40,17 @@ describe("getCommitMeaning", () => { | |||
["chore(deps): release", "release"], | ||||
["chore(deps): release 1.2.3", "release"], | ||||
["chore(deps): release v1.2.3", "release"], | ||||
// Breaking changes are meaningful no matter the type of the commit. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Style] Just nitpicking here, I think the comment is explanatory from the test cases.
Suggested change
|
||||
["chore!: message", "meaningful"], | ||||
["docs!: message", "meaningful"], | ||||
["style!: message", "meaningful"], | ||||
["chore!: release", "meaningful"], | ||||
["chore: bump\n\nBREAKING CHANGE: breaks things", "meaningful"], | ||||
["chore: bump\n\nBREAKING-CHANGE: breaks things", "meaningful"], | ||||
["docs: bump\n\nBREAKING CHANGE: breaks things", "meaningful"], | ||||
["docs: bump\n\nBREAKING-CHANGE: breaks things", "meaningful"], | ||||
["style: bump\n\nBREAKING CHANGE: breaks things", "meaningful"], | ||||
["style: bump\n\nBREAKING-CHANGE: breaks things", "meaningful"], | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Testing] Thinking about test edge cases...
|
||||
])("returns %j for %s", (input, expected) => { | ||||
expect(getCommitMeaning(input)).toEqual(expected); | ||||
}); | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import conventionalCommitsParser from "conventional-commits-parser"; | ||
import { | ||
parser, | ||
toConventionalChangelogFormat, | ||
} from "@conventional-commits/parser"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Refactor] 🤔 What do you think about instead using a small regex to check for a subject, optionally an area/scope, and Maybe: also filing an issue on |
||
const alwaysMeaningfulTypes = new Set(["feat", "fix", "perf"]); | ||
|
||
|
@@ -8,22 +11,31 @@ const releaseCommitTester = | |
/^(?:chore(?:\(.*\))?:?)?\s*release|v?\d+\.\d+\.\d+/; | ||
|
||
export function getCommitMeaning(message: string) { | ||
// Some types are always meaningful or ignored, regardless of potentially release-like messages | ||
const { type } = conventionalCommitsParser.sync(message); | ||
if (type) { | ||
if (alwaysMeaningfulTypes.has(type)) { | ||
let type = undefined; | ||
try { | ||
const messageAst = parser(message); | ||
const commit = toConventionalChangelogFormat(messageAst); | ||
type = commit.type; | ||
|
||
// Some types are always meaningful or ignored, regardless of potentially release-like messages | ||
if ( | ||
alwaysMeaningfulTypes.has(type) || | ||
commit.notes.some(({ title }) => title === "BREAKING CHANGE") | ||
) { | ||
return "meaningful"; | ||
} | ||
|
||
if (alwaysIgnoredTypes.has(type)) { | ||
return { type }; | ||
} | ||
} catch { | ||
/* empty */ | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Refactor] I'm not a big fan of |
||
|
||
// If we've hit a release commit, we know we don't need to release | ||
if (releaseCommitTester.test(message)) { | ||
return "release"; | ||
} | ||
|
||
return { type: type ?? undefined }; | ||
return { type }; | ||
} |
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.
This jalopy does not recognize the
feat!: message
form of commits.