From 37e5d94373e0a55ccb58dceade6a8336f171eeb8 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Wed, 24 Dec 2025 23:49:37 +0545 Subject: [PATCH] feat(devgen): enhance sanitize_ai_commit_message to handle bolding and labels - Improve header detection by stripping bolding and cleaning labels like "1. Title:", "### Message:", etc. - Stop processing lines when encountering a sponsor section ``` --- devgen/utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/devgen/utils.py b/devgen/utils.py index e2cbca7..5a02790 100644 --- a/devgen/utils.py +++ b/devgen/utils.py @@ -57,13 +57,23 @@ def sanitize_ai_commit_message(raw_text: str) -> str: for line in lines: stripped = line.strip() if not found_header: - if header_pattern.match(stripped): + # First, strip bolding if it wraps the whole line or parts of it + # This is simpler than handling it in the regex + candidate = stripped.replace("**", "").strip() + + # Clean the line by removing labels like "1. Title:", "### Message:", etc. + clean_line = re.sub( + r"^(#+\s+)?(\d+\.?|\*|-)?\s*(Title|Commit Message|Message):\s*", + "", + candidate, + flags=re.IGNORECASE, + ).strip() + + if header_pattern.match(clean_line): found_header = True - # Remove bolding if present - clean_line = stripped.replace("**", "").strip() cleaned_lines.append(clean_line) else: - # If we hit another header or a known separator, we stop (optional, but keep for now) + # If we hit another header or a known separator, we stop if "**Sponsor**" in line: break cleaned_lines.append(line)