Skip to content

Commit

Permalink
feat: add ability to mark commit as breaking
Browse files Browse the repository at this point in the history
Signed-off-by: Ardalan Amini <[email protected]>
  • Loading branch information
ardalanamini committed Apr 29, 2023
1 parent 4b435e2 commit f676806
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion action/index.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface ScopeGroupI {
}

interface LogI {
breaking: boolean;
description: string;
references: string[];
}
Expand Down Expand Up @@ -97,7 +98,7 @@ export async function generateChangelog(lastSha?: string): Promise<string> {

debug(`commit message -> ${ message }`);

let { type, scope, description, pr, flag } = parseCommitMessage(message);
let { type, scope, description, pr, flag, breaking } = parseCommitMessage(message);

if (!description) continue;

Expand Down Expand Up @@ -138,6 +139,7 @@ export async function generateChangelog(lastSha?: string): Promise<string> {

if (log == null) {
log = {
breaking,
description,
references: [],
};
Expand Down Expand Up @@ -179,8 +181,8 @@ export async function generateChangelog(lastSha?: string): Promise<string> {
prefix = " ";
}

for (const { description, references } of logs) {
let line = `${ prefix }* ${ description }`;
for (const { breaking, description, references } of logs) {
let line = `${ prefix }* ${ breaking ? "**breaking: **" : "" }${ description }`;

if (references.length > 0) line += ` (${ references.join(", ") })`;

Expand Down
24 changes: 21 additions & 3 deletions src/utils/parse-commit-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,26 @@
*
*/

const REGEX = /^(?<type>[^:()]*)(?:\((?<scope>[^()]*?)\)|): *(?<description>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
const REGEX = /^(?<type>[^!:()]*)(?:\((?<scope>[^!()]*?)\)|)(?<breaking>!?): *(?<description>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;

export function parseCommitMessage(message: string): { description?: string; flag?: string; pr?: `${ number }`; scope?: string; type?: string } {
return REGEX.exec(message)?.groups ?? {};
export function parseCommitMessage(message: string): ParsedCommitMessageI {
const { description, flag, pr, scope, type, breaking } = REGEX.exec(message)?.groups ?? {};

return {
breaking: !!breaking,
description,
flag,
pr,
scope,
type,
};
}

export interface ParsedCommitMessageI {
breaking: boolean;
description?: string;
flag?: string;
pr?: string;
scope?: string;
type?: string;
}

0 comments on commit f676806

Please sign in to comment.