Skip to content

Commit

Permalink
feat(commit): capture ! after the scope
Browse files Browse the repository at this point in the history
This can handle this case: add(commits)!: something.
  • Loading branch information
arsham committed May 8, 2022
1 parent 26e0747 commit 185d73c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
7 changes: 4 additions & 3 deletions commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

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

Expand All @@ -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, "!")
}
Expand Down
42 changes: 42 additions & 0 deletions commit/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down

0 comments on commit 185d73c

Please sign in to comment.