From 92bfca19b8a9287dddbf9eb2e7572637096c9791 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 6 Oct 2024 07:20:11 -0400 Subject: [PATCH] fix: support multi-line body --- cmd/joj3/conf.go | 2 +- cmd/joj3/conf_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 9af1972..6e63847 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -74,7 +74,7 @@ type ConventionalCommit struct { } func parseConventionalCommit(commit string) (*ConventionalCommit, error) { - re := regexp.MustCompile(`^(\w+)(\(([^)]+)\))?!?: (.+)(\n\n(.+))?(\n\n(.+))?$`) + re := regexp.MustCompile(`(?s)^(\w+)(\(([^)]+)\))?!?: (.+?)(\n\n(.+?))?(\n\n(.+))?$`) matches := re.FindStringSubmatch(strings.TrimSpace(commit)) if matches == nil { return nil, fmt.Errorf("invalid conventional commit format") diff --git a/cmd/joj3/conf_test.go b/cmd/joj3/conf_test.go index 5d01d6e..0906cc3 100644 --- a/cmd/joj3/conf_test.go +++ b/cmd/joj3/conf_test.go @@ -69,6 +69,30 @@ func TestParseConventionalCommit(t *testing.T) { want: nil, wantErr: true, }, + { + name: "Multi-line body", + commit: "feat(h1/e2): group (#86)\n\nReviewed-on: https://focs.ji.sjtu.edu.cn/git/test/test/pulls/86\nReviewed-by: foo \nReviewed-by: bar \nReviewed-by: nobody \n", + want: &ConventionalCommit{ + Type: "feat", + Scope: "h1/e2", + Description: "group (#86)", + Body: "Reviewed-on: https://focs.ji.sjtu.edu.cn/git/test/test/pulls/86\nReviewed-by: foo \nReviewed-by: bar \nReviewed-by: nobody ", + Footer: "", + }, + wantErr: false, + }, + { + name: "Multi-line body with footer", + commit: "feat(h1/e2): group (#86)\n\nReviewed-on: https://focs.ji.sjtu.edu.cn/git/test/test/pulls/86\nReviewed-by: foo \nReviewed-by: bar \nReviewed-by: nobody \n\nFooter here\n", + want: &ConventionalCommit{ + Type: "feat", + Scope: "h1/e2", + Description: "group (#86)", + Body: "Reviewed-on: https://focs.ji.sjtu.edu.cn/git/test/test/pulls/86\nReviewed-by: foo \nReviewed-by: bar \nReviewed-by: nobody ", + Footer: "Footer here", + }, + wantErr: false, + }, } for _, tt := range tests {