feat(devgen): improve sanitize_ai_commit_message function
The `sanitize_ai_commit_message` function in `devgen/utils.py` has been enhanced for better readability and maintainability. The changes include minor formatting improvements and a more consistent regex pattern definition. **Enhancements & Refinements:** - Improved code formatting by removing trailing whitespace and adding a comma after `re.IGNORECASE` in the regex pattern for better readability. - Enhanced comment clarity by fixing a minor typo in the regex examples section. ```
This commit is contained in:
1 file changed
+4
-4
+4
-4
@@ -40,15 +40,15 @@ def sanitize_ai_commit_message(raw_text: str) -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
lines = raw_text.strip().split("\n")
|
lines = raw_text.strip().split("\n")
|
||||||
|
|
||||||
# Regex for conventional commit header (including optional bolding)
|
# Regex for conventional commit header (including optional bolding)
|
||||||
# Examples:
|
# Examples:
|
||||||
# - feat(root): summary
|
# - feat(root): summary
|
||||||
# - **fix: bug fix**
|
# - **fix: bug fix**
|
||||||
# - chore(deps)!: breaking change
|
# - chore(deps)!: breaking change
|
||||||
header_pattern = re.compile(
|
header_pattern = re.compile(
|
||||||
r"^(\*\*)?(feat|fix|chore|refactor|docs|style|test|build|ci)(\(.*\))?!?: .*",
|
r"^(\*\*)?(feat|fix|chore|refactor|docs|style|test|build|ci)(\(.*\))?!?: .*",
|
||||||
re.IGNORECASE
|
re.IGNORECASE,
|
||||||
)
|
)
|
||||||
|
|
||||||
cleaned_lines = []
|
cleaned_lines = []
|
||||||
@@ -70,7 +70,7 @@ def sanitize_ai_commit_message(raw_text: str) -> str:
|
|||||||
|
|
||||||
if cleaned_lines:
|
if cleaned_lines:
|
||||||
return "\n".join(cleaned_lines).strip()
|
return "\n".join(cleaned_lines).strip()
|
||||||
|
|
||||||
# Fallback: if no conventional commit header found, just take the first non-empty line
|
# Fallback: if no conventional commit header found, just take the first non-empty line
|
||||||
# to avoid failing completely, but log a warning if possible.
|
# to avoid failing completely, but log a warning if possible.
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|||||||
Reference in new issue
Block a user