Skip to content

Commit 95b8af3

Browse files
authoredDec 8, 2024
fix: fix parsing a breaking change commit with scope (#61)
1 parent bb02365 commit 95b8af3

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed
 

‎src/print-commits.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,21 @@ export function parseCommits(raw: string) {
3636
.map((line): ParsedCommit => {
3737
const [hash, ...parts] = line.split(' ')
3838
const message = parts.join(' ')
39-
const match = message.match(/^(\w+)(!)?(\([^)]+\))?:(.*)$/)
39+
const match = message.match(/^(\w+)(!)?(\([^)]+\))?(!)?:(.*)$/)
4040
if (match) {
4141
let color = messageColorMap[match[1].toLowerCase()] || ((c: string) => c)
42-
if (match[2] === '!') {
42+
const breaking = match[2] === '!' || match[4] === '!'
43+
if (breaking) {
4344
color = s => c.inverse(c.red(s))
4445
}
45-
const tag = [match[1], match[2]].filter(Boolean).join('')
46+
const tag = [match[1], match[2], match[4]].filter(Boolean).join('')
4647
const scope = match[3] || ''
4748
return {
4849
hash,
4950
tag,
50-
message: match[4].trim(),
51+
message: match[5].trim(),
5152
scope,
52-
breaking: match[2] === '!',
53+
breaking,
5354
color,
5455
}
5556
}

‎test/parse-commits.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ bfad9f238 fix!(extractor-arbitrary-variants): skip extracting encoded html entit
1919
35297359b docs(rules): explain symbols.layer in symbols docs (#4145)
2020
9be7b299d feat(core): add symbols.layer (#4143)
2121
bd4d8e998 docs(config): layers using variants (#4144)
22+
67f3237dc refactor!: make arbitrary variants extractor callable (#4239)
23+
5420b1316 feat(core)!: deprecate \`new UnoGenerator\`, make \`createGenerator()\` async (#4268)
2224
`
2325

2426
it('parseCommits', async () => {
@@ -27,6 +29,22 @@ it('parseCommits', async () => {
2729
expect(parsed)
2830
.toMatchInlineSnapshot(`
2931
[
32+
{
33+
"breaking": true,
34+
"color": [Function],
35+
"hash": "5420b1316",
36+
"message": "deprecate \`new UnoGenerator\`, make \`createGenerator()\` async (#4268)",
37+
"scope": "(core)",
38+
"tag": "feat!",
39+
},
40+
{
41+
"breaking": true,
42+
"color": [Function],
43+
"hash": "67f3237dc",
44+
"message": "make arbitrary variants extractor callable (#4239)",
45+
"scope": "",
46+
"tag": "refactor!",
47+
},
3048
{
3149
"breaking": false,
3250
"color": [Function],

0 commit comments

Comments
 (0)
Please sign in to comment.