From 1c7f7a8a9e37e3188c7aa5f26e709038a05c3a70 Mon Sep 17 00:00:00 2001 From: Amolith Date: Thu, 23 Oct 2025 18:47:10 -0600 Subject: [PATCH] feat: require BREAKING CHANGE footer with -B flag When the -B flag is used to mark a commit as a breaking change, the tool now validates that the body contains a BREAKING CHANGE: or BREAKING CHANGES: footer. If not present, it returns a descriptive error instructing users to document breaking change details in this footer. Implements: bug-e75a648 Co-authored-by: Crush --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index 8e4b62f3dbb3daddfdeac1200c70f789483f9e39..fb1c037d1880accb075ff0ad1b7d5e72c54eec4e 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,10 @@ formatted-commit upgrade -a return err } + if breakingChange && !hasBreakingChangeFooter(body) { + return fmt.Errorf("breaking change flag (-B) requires a BREAKING CHANGE: or CHANGES: footer at the end of the body. It instructs users how to resolve the breaking changes resulting from this commit") + } + var commitMsg strings.Builder commitMsg.WriteString(subject) @@ -169,6 +173,17 @@ func buildAndValidateSubject(commitType, scope, message string, breaking bool) ( return result, nil } +func hasBreakingChangeFooter(body string) bool { + lines := strings.Split(body, "\n") + for _, line := range lines { + trimmed := strings.TrimSpace(line) + if strings.HasPrefix(trimmed, "BREAKING CHANGE:") || strings.HasPrefix(trimmed, "BREAKING CHANGES:") { + return true + } + } + return false +} + func main() { ctx := context.Background()