refactor(commitgen): improve emoji handling and sanitization in commit message generation

This commit is contained in:
sankalp committed 2025-08-25 14:55:23 +05:45
1 parent 5fa1d106a2
commit 341b52f287
2 files changed
+14 -17

No files matched your search

+3 -4
View File
@@ -11,16 +11,15 @@
🔄 Changed 🔄 Changed
- Replaced Ruff linter with Black - Replaced Ruff linter with Black
🐛 Fixed
- Improved changelog generation and sanitization of AI output - Improved changelog generation and sanitization of AI output
- Improved changelog generation to handle existing files and duplicate headers - Improved changelog generation to handle existing files and duplicate headers
🗑️ Removed
- Removed duplicate changelog entries - Removed duplicate changelog entries
📝 Documentation 📝 Documentation
- Updated changelog for v0.1.0 release
- Updated changelog for v0.1.1 release
- Recommended installation using pipx and uv - Recommended installation using pipx and uv
- Updated changelog for v0.1.1 release
## v0.1.0 ## v0.1.0
+11 -13
View File
@@ -96,7 +96,7 @@ Output ONLY the commit message in the correct format{" with emoji" if self.use_e
else: else:
message = lines[0] if lines else "🔧 chore: update code" message = lines[0] if lines else "🔧 chore: update code"
# Apply or remove emoji based on configuration # Apply or remove emoji based on configuration (strict removal when disabled)
if self.use_emoji: if self.use_emoji:
if not any( if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"] emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
@@ -116,13 +116,12 @@ Output ONLY the commit message in the correct format{" with emoji" if self.use_e
elif message.startswith("chore"): elif message.startswith("chore"):
message = "🔧 " + message message = "🔧 " + message
else: else:
message = "🔧 " + message # fallback message = "🔧 " + message
else: else:
# Strip known emojis if present # Remove any known emojis anywhere in the message
for emoji in ["✨ ", "🐛 ", "📚 ", "💅 ", "♻️ ", "✅ ", "🔧 "]: for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]:
if message.startswith(emoji): message = message.replace(emoji, "")
message = message[len(emoji) :] message = " ".join(message.split())
break
return message return message
@@ -220,7 +219,7 @@ Output ONLY the commit message in the correct format{" with emoji" if self.use_e
else: else:
message = lines[0] if lines else "🔧 chore: update code" message = lines[0] if lines else "🔧 chore: update code"
# Ensure proper emoji prefix # Ensure proper emoji prefix or strip strictly according to config
if self.use_emoji: if self.use_emoji:
if not any( if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"] emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
@@ -240,12 +239,11 @@ Output ONLY the commit message in the correct format{" with emoji" if self.use_e
elif message.startswith("chore"): elif message.startswith("chore"):
message = "🔧 " + message message = "🔧 " + message
else: else:
message = "🔧 " + message # fallback message = "🔧 " + message
else: else:
for emoji in ["✨ ", "🐛 ", "📚 ", "💅 ", "♻️ ", "✅ ", "🔧 "]: for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]:
if message.startswith(emoji): message = message.replace(emoji, "")
message = message[len(emoji) :] message = " ".join(message.split())
break
return message return message