generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from JoshuaKGoldberg/more-commit-meanings
feat: add understanding of more commit types
- Loading branch information
Showing
6 changed files
with
99 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { getCommitMeaning } from "./getCommitMeaning.js"; | ||
|
||
describe("getCommitMeaning", () => { | ||
it.each([ | ||
["chore", { type: undefined }], | ||
["chore: deps", { type: "chore" }], | ||
["chore(deps): bump", { type: "chore" }], | ||
["docs", { type: undefined }], | ||
["docs: bump", { type: "docs" }], | ||
["docs: message", { type: "docs" }], | ||
["feat", { type: undefined }], | ||
["feat: bump", "meaningful"], | ||
["feat: bump version to 1.2.3", "meaningful"], | ||
["feat: message", "meaningful"], | ||
["fix", { type: undefined }], | ||
["fix: bump", "meaningful"], | ||
["fix: bump version to 1.2.3", "meaningful"], | ||
["fix: message", "meaningful"], | ||
["perf", { type: undefined }], | ||
["perf: bump", "meaningful"], | ||
["perf: bump version to 1.2.3", "meaningful"], | ||
["perf: message", "meaningful"], | ||
["style", { type: undefined }], | ||
["style: bump", { type: "style" }], | ||
["style: bump version to 1.2.3", { type: "style" }], | ||
["style: message", { type: "style" }], | ||
["0.0.0", "release"], | ||
["v0.0.0", "release"], | ||
["1.2.3", "release"], | ||
["v1.2.3", "release"], | ||
["1.23.456", "release"], | ||
["v1.23.456", "release"], | ||
["12.345.6789", "release"], | ||
["v12.345.6789", "release"], | ||
["chore: release", "release"], | ||
["chore: release 1.2.3", "release"], | ||
["chore: release v1.2.3", "release"], | ||
["chore(deps): release", "release"], | ||
["chore(deps): release 1.2.3", "release"], | ||
["chore(deps): release v1.2.3", "release"], | ||
])("returns %j for %s", (input, expected) => { | ||
expect(getCommitMeaning(input)).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import conventionalCommitsParser from "conventional-commits-parser"; | ||
|
||
const alwaysMeaningfulTypes = new Set(["feat", "fix", "perf"]); | ||
|
||
const alwaysIgnoredTypes = new Set(["docs", "refactor", "style", "test"]); | ||
|
||
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)) { | ||
return "meaningful"; | ||
} | ||
if (alwaysIgnoredTypes.has(type)) { | ||
return { type }; | ||
} | ||
} | ||
|
||
// 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 }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters