Skip to content

Commit f676806

Browse files
committed
feat: add ability to mark commit as breaking
Signed-off-by: Ardalan Amini <[email protected]>
1 parent 4b435e2 commit f676806

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

action/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/changelog.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface ScopeGroupI {
4848
}
4949

5050
interface LogI {
51+
breaking: boolean;
5152
description: string;
5253
references: string[];
5354
}
@@ -97,7 +98,7 @@ export async function generateChangelog(lastSha?: string): Promise<string> {
9798

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

100-
let { type, scope, description, pr, flag } = parseCommitMessage(message);
101+
let { type, scope, description, pr, flag, breaking } = parseCommitMessage(message);
101102

102103
if (!description) continue;
103104

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

139140
if (log == null) {
140141
log = {
142+
breaking,
141143
description,
142144
references: [],
143145
};
@@ -179,8 +181,8 @@ export async function generateChangelog(lastSha?: string): Promise<string> {
179181
prefix = " ";
180182
}
181183

182-
for (const { description, references } of logs) {
183-
let line = `${ prefix }* ${ description }`;
184+
for (const { breaking, description, references } of logs) {
185+
let line = `${ prefix }* ${ breaking ? "**breaking: **" : "" }${ description }`;
184186

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

src/utils/parse-commit-message.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,26 @@
2323
*
2424
*/
2525

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

28-
export function parseCommitMessage(message: string): { description?: string; flag?: string; pr?: `${ number }`; scope?: string; type?: string } {
29-
return REGEX.exec(message)?.groups ?? {};
28+
export function parseCommitMessage(message: string): ParsedCommitMessageI {
29+
const { description, flag, pr, scope, type, breaking } = REGEX.exec(message)?.groups ?? {};
30+
31+
return {
32+
breaking: !!breaking,
33+
description,
34+
flag,
35+
pr,
36+
scope,
37+
type,
38+
};
39+
}
40+
41+
export interface ParsedCommitMessageI {
42+
breaking: boolean;
43+
description?: string;
44+
flag?: string;
45+
pr?: string;
46+
scope?: string;
47+
type?: string;
3048
}

0 commit comments

Comments
 (0)