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(git): support parse git messages that have prefix emoji #146

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function parseCommits(
// https://www.conventionalcommits.org/en/v1.0.0/
// https://regex101.com/r/FSfNvA/1
const ConventionalCommitRegex =
/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
/(?<emoji>:.+:|(\uD83C[\uDF00-\uDFFF])|(\uD83D[\uDC00-\uDE4F\uDE80-\uDEFF])|[\u2600-\u2B55])?( *)?(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
const CoAuthoredByRegex = /co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim;
const PullRequestRE = /\([ a-z]*(#\d+)\s*\)/gm;
const IssueRE = /(#\d+)/gm;
Expand Down
84 changes: 84 additions & 0 deletions test/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,90 @@ describe("git", () => {
);
});

test("parse commit with emoji", async () => {
const rawCommitEmojiList = [
{
message: "πŸš€ feat: add emoji support",
shortHash: "0000000",
body: "this is a emoji commit",
author: {
email: "[email protected]",
name: "Jannchie",
},
},
{
message: ":bug: fix: this is a text emoji",
shortHash: "0000001",
body: "this is a emoji commit",
author: {
email: "[email protected]",
name: "Jannchie",
},
},
{
message: ":bug: fix(scope): this is a text emoji with scope",
shortHash: "0000001",
body: "this is a emoji commit",
author: {
email: "[email protected]",
name: "Jannchie",
},
},
];
const parsed = parseCommits(
rawCommitEmojiList,
await loadChangelogConfig(process.cwd(), {})
);

expect(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parsed.map(({ body: _, author: __, authors: ___, ...rest }) => rest)
).toMatchObject([
{
message: "πŸš€ feat: add emoji support",
shortHash: "0000000",
description: "add emoji support",
type: "feat",
scope: "",
references: [
{
value: "0000000",
type: "hash",
},
],
isBreaking: false,
},
{
message: ":bug: fix: this is a text emoji",
shortHash: "0000001",
description: "this is a text emoji",
type: "fix",
scope: "",
references: [
{
value: "0000001",
type: "hash",
},
],
isBreaking: false,
},
{
message: ":bug: fix(scope): this is a text emoji with scope",
shortHash: "0000001",
description: "this is a text emoji with scope",
type: "fix",
scope: "scope",
references: [
{
value: "0000001",
type: "hash",
},
],
isBreaking: false,
},
]);
});

test("parse", async () => {
const COMMIT_FROM = "1cb15d5dd93302ebd5ff912079ed584efcc6703b";
const COMMIT_TO = "3828bda8c45933396ddfa869d671473231ce3c95";
Expand Down