diff --git a/commit/commit.go b/commit/commit.go index 8da7d51..ba3e8ac 100644 --- a/commit/commit.go +++ b/commit/commit.go @@ -7,7 +7,7 @@ import ( ) var ( - descRe = regexp.MustCompile(`^\s*([[:alpha:]]+!?)\(?([[:alpha:],_-]+)?\)?:?(.*)`) + descRe = regexp.MustCompile(`^\s*([[:alpha:]]+!?)\(?([[:alpha:],_-]+)?\)?(!)?:?(.*)`) refRe = regexp.MustCompile(`[[:alpha:]]+\s+#\d+`) ) @@ -28,10 +28,11 @@ func GroupFromCommit(msg string) Group { matches := descRe.FindStringSubmatch(msg) verb := matches[1] subject := matches[2] - desc := matches[3] + verbBreak := matches[3] + desc := matches[4] breaking := false - if strings.HasSuffix(verb, "!") { + if strings.HasSuffix(verb, "!") || verbBreak != "" { breaking = true verb = strings.TrimSuffix(verb, "!") } diff --git a/commit/commit_test.go b/commit/commit_test.go index 673ad6c..71190d1 100644 --- a/commit/commit_test.go +++ b/commit/commit_test.go @@ -199,6 +199,30 @@ func testGroupParseGroupsMultipleGroups(t *testing.T) { } func testGroupParseGroupsBreakingSign(t *testing.T) { + t.Run("NoScope", testGroupParseGroupsBreakingSignNoScope) + t.Run("BeforeScope", testGroupParseGroupsBreakingSignBeforeScope) + t.Run("AfterScope", testGroupParseGroupsBreakingSignAfterScope) +} + +func testGroupParseGroupsBreakingSignNoScope(t *testing.T) { + t.Parallel() + logs := []string{ + "ref: nothing important", + "ref!: this is a test", + } + got := commit.ParseGroups(logs) + + want := strings.Join([]string{ + "### Refactor\n", + "- Nothing important", + "- This is a test [**BREAKING CHANGE**]", + }, "\n") + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("(-want +got):\n%s", diff) + } +} + +func testGroupParseGroupsBreakingSignBeforeScope(t *testing.T) { t.Parallel() logs := []string{ "ref: nothing important", @@ -216,6 +240,24 @@ func testGroupParseGroupsBreakingSign(t *testing.T) { } } +func testGroupParseGroupsBreakingSignAfterScope(t *testing.T) { + t.Parallel() + logs := []string{ + "ref: nothing important", + "ref(repo)!: this is a test", + } + got := commit.ParseGroups(logs) + + want := strings.Join([]string{ + "### Refactor\n", + "- Nothing important", + "- **Repo:** This is a test [**BREAKING CHANGE**]", + }, "\n") + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("(-want +got):\n%s", diff) + } +} + func testGroupParseGroupsBreakingFooter(t *testing.T) { t.Parallel() logs := []string{