From 3ccbb907ff31b6f01f6e47c827f599daaee1105c 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 283913d7bb62794ac003573a414dccd2d4f7ecc1..db3880e31b59a8c3dbf906c6fc47bc6502dfd68c 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,10 @@ formatted-commit -t refactor -s "web/git-bug" -m "fancy shmancy" \ 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) @@ -151,6 +155,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()