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: include breaking change message if provided #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface GitCommit extends RawGitCommit {
references: Reference[];
authors: GitCommitAuthor[];
isBreaking: boolean;
breakingChangeMessage?: string;
}

export async function getLastGitTag() {
Expand Down Expand Up @@ -101,7 +102,8 @@ export function parseCommits(
// https://regex101.com/r/FSfNvA/1
const ConventionalCommitRegex =
/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
const CoAuthoredByRegex = /co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim;
const CoAuthoredByRegex = /^co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim;
const BreakingChangeRegex = /^BREAKING CHANGE: (?<message>.+)$/gm;
const PullRequestRE = /\([ a-z]*(#\d+)\s*\)/gm;
const IssueRE = /(#\d+)/gm;

Expand Down Expand Up @@ -146,6 +148,13 @@ export function parseGitCommit(
});
}

// Find breaking change message
let breakingChangeMessage: string;
if(isBreaking) {
const match = BreakingChangeRegex.exec(commit.message);
breakingChangeMessage = match.groups?.message
}

return {
...commit,
authors,
Expand All @@ -154,5 +163,6 @@ export function parseGitCommit(
scope,
references,
isBreaking,
breakingChangeMessage,
};
}
6 changes: 3 additions & 3 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function generateMarkDown(
const line = formatCommit(commit, config);
markdown.push(line);
if (commit.isBreaking) {
breakingChanges.push(line);
breakingChanges.push(`- ${commit.breakingChangeMessage}` ?? line);
}
}
}
Expand Down Expand Up @@ -176,8 +176,8 @@ function formatName(name = "") {
.join(" ");
}

function groupBy(items: any[], key: string) {
const groups = {};
function groupBy<TItem>(items: TItem[], key: string) {
const groups: Record<string, TItem[]> = {};
Comment on lines +179 to +180
Copy link
Author

Choose a reason for hiding this comment

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

This function was returning any for me locally, seemed useful to provide types

for (const item of items) {
groups[item[key]] = groups[item[key]] || [];
groups[item[key]].push(item);
Expand Down