Skip to content

Commit 185d73c

Browse files
committed
feat(commit): capture ! after the scope
This can handle this case: add(commits)!: something.
1 parent 26e0747 commit 185d73c

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

commit/commit.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
var (
10-
descRe = regexp.MustCompile(`^\s*([[:alpha:]]+!?)\(?([[:alpha:],_-]+)?\)?:?(.*)`)
10+
descRe = regexp.MustCompile(`^\s*([[:alpha:]]+!?)\(?([[:alpha:],_-]+)?\)?(!)?:?(.*)`)
1111
refRe = regexp.MustCompile(`[[:alpha:]]+\s+#\d+`)
1212
)
1313

@@ -28,10 +28,11 @@ func GroupFromCommit(msg string) Group {
2828
matches := descRe.FindStringSubmatch(msg)
2929
verb := matches[1]
3030
subject := matches[2]
31-
desc := matches[3]
31+
verbBreak := matches[3]
32+
desc := matches[4]
3233

3334
breaking := false
34-
if strings.HasSuffix(verb, "!") {
35+
if strings.HasSuffix(verb, "!") || verbBreak != "" {
3536
breaking = true
3637
verb = strings.TrimSuffix(verb, "!")
3738
}

commit/commit_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,30 @@ func testGroupParseGroupsMultipleGroups(t *testing.T) {
199199
}
200200

201201
func testGroupParseGroupsBreakingSign(t *testing.T) {
202+
t.Run("NoScope", testGroupParseGroupsBreakingSignNoScope)
203+
t.Run("BeforeScope", testGroupParseGroupsBreakingSignBeforeScope)
204+
t.Run("AfterScope", testGroupParseGroupsBreakingSignAfterScope)
205+
}
206+
207+
func testGroupParseGroupsBreakingSignNoScope(t *testing.T) {
208+
t.Parallel()
209+
logs := []string{
210+
"ref: nothing important",
211+
"ref!: this is a test",
212+
}
213+
got := commit.ParseGroups(logs)
214+
215+
want := strings.Join([]string{
216+
"### Refactor\n",
217+
"- Nothing important",
218+
"- This is a test [**BREAKING CHANGE**]",
219+
}, "\n")
220+
if diff := cmp.Diff(want, got); diff != "" {
221+
t.Errorf("(-want +got):\n%s", diff)
222+
}
223+
}
224+
225+
func testGroupParseGroupsBreakingSignBeforeScope(t *testing.T) {
202226
t.Parallel()
203227
logs := []string{
204228
"ref: nothing important",
@@ -216,6 +240,24 @@ func testGroupParseGroupsBreakingSign(t *testing.T) {
216240
}
217241
}
218242

243+
func testGroupParseGroupsBreakingSignAfterScope(t *testing.T) {
244+
t.Parallel()
245+
logs := []string{
246+
"ref: nothing important",
247+
"ref(repo)!: this is a test",
248+
}
249+
got := commit.ParseGroups(logs)
250+
251+
want := strings.Join([]string{
252+
"### Refactor\n",
253+
"- Nothing important",
254+
"- **Repo:** This is a test [**BREAKING CHANGE**]",
255+
}, "\n")
256+
if diff := cmp.Diff(want, got); diff != "" {
257+
t.Errorf("(-want +got):\n%s", diff)
258+
}
259+
}
260+
219261
func testGroupParseGroupsBreakingFooter(t *testing.T) {
220262
t.Parallel()
221263
logs := []string{

0 commit comments

Comments
 (0)