From 08b43cc51b2f8975144fb61afddb5cb222890e09 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:37:58 +0200 Subject: [PATCH] refactor(validation): simplify regex and error messages --- internal/validation/validation.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 4d48e4a..8c3123e 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -13,33 +13,26 @@ func ValidateConventionalCommit(commit string) error { // type!: description // or // type: description - re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P[a-z].+)$`) + re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P.+)$`) match := re.FindStringSubmatch(commit) if len(match) == 0 { - return fmt.Errorf("Invalid PR title") + return fmt.Errorf("invalid commit format") } typeIndex := re.SubexpIndex("type") scopeIndex := re.SubexpIndex("scope") breakingIndex := re.SubexpIndex("breaking") - descriptionIndex := re.SubexpIndex("description") commitType := match[typeIndex] scope := match[scopeIndex] breaking := match[breakingIndex] - description := match[descriptionIndex] // Type MUST be lowercase if commitType != strings.ToLower(commitType) { return fmt.Errorf("type must be lowercase") } - // Description MUST start with lowercase - if description != strings.ToLower(description) { - return fmt.Errorf("description must start with lowercase") - } - // Scope MUST be lowercase if scope != "" && scope != strings.ToLower(scope) { return fmt.Errorf("scope must be lowercase")