feat: require BREAKING CHANGE footer with -B flag

Amolith and Crush created

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 <crush@charm.land>

Change summary

main.go | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Detailed changes

main.go 🔗

@@ -62,6 +62,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)
 
@@ -164,6 +168,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()