fix: support multi-line body
This commit is contained in:
parent
279dce65d1
commit
92bfca19b8
|
@ -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")
|
||||
|
|
|
@ -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 <foo@sjtu.edu.cn>\nReviewed-by: bar <bar@sjtu.edu.cn>\nReviewed-by: nobody <nobody@sjtu.edu.cn>\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 <foo@sjtu.edu.cn>\nReviewed-by: bar <bar@sjtu.edu.cn>\nReviewed-by: nobody <nobody@sjtu.edu.cn>",
|
||||
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 <foo@sjtu.edu.cn>\nReviewed-by: bar <bar@sjtu.edu.cn>\nReviewed-by: nobody <nobody@sjtu.edu.cn>\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 <foo@sjtu.edu.cn>\nReviewed-by: bar <bar@sjtu.edu.cn>\nReviewed-by: nobody <nobody@sjtu.edu.cn>",
|
||||
Footer: "Footer here",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in New Issue
Block a user