feat: add emoji option to cli and config to control emoji prefixes

This commit is contained in:
sankalp committed 2025-08-25 13:54:51 +05:45
1 parent c80a6caca0
commit b09b5f676e
3 files changed
+73 -41

No files matched your search

+7 -1
View File
@@ -108,6 +108,7 @@ output_format: text
# Commit Settings
conventional_commits: true
emoji: false
# Repository Settings
repositories: []
@@ -142,6 +143,9 @@ devtools config set max_tokens 150
# Set conventional commit style (optional, default is true)
devtools config set conventional_commits true
# Enable or disable emojis in commit messages (optional, default is false)
devtools config set emoji false
# Set output format (optional, e.g., text or markdown)
devtools config set output_format text
@@ -197,9 +201,11 @@ devtools commit generate [OPTIONS]
- `--no-stage` Skip automatic staging of changes
- `--sign` Sign commits with GPG
- `--temperature FLOAT` AI temperature (0.0-1.0)
- `--emoji/--no-emoji` Include emoji prefixes (default: disabled)
Commit messages follow the conventional format with emojis:
Commit messages follow the conventional format (emojis optional):
When emojis are enabled, these prefixes are used:
- ✨ feat: New feature
- 🐛 fix: Bug fix
- 📚 docs: Documentation
+4 -1
View File
@@ -31,7 +31,8 @@ def cli():
@click.option('--no-stage', is_flag=True, help='Skip automatic staging of changes')
@click.option('--sign', is_flag=True, help='Sign commits with GPG')
@click.option('--temperature', type=float, help='AI temperature (0.0-1.0)')
def generate(files: tuple, repo: str, commit: bool, push: bool, conventional: bool, no_stage: bool, sign: bool, temperature: float):
@click.option('--emoji/--no-emoji', default=False, help='Include emoji prefixes in commit messages')
def generate(files: tuple, repo: str, commit: bool, push: bool, conventional: bool, no_stage: bool, sign: bool, temperature: float, emoji: bool):
"""Generate commit messages for staged changes"""
try:
with Progress(
@@ -41,6 +42,8 @@ def generate(files: tuple, repo: str, commit: bool, push: bool, conventional: bo
) as progress:
# Initialize services
config = Config()
# Override emoji setting for this invocation without persisting to disk
config._config["emoji"] = "true" if emoji else "false"
git_service = CommitGenGitService(config)
ai_service = CommitGenerator(config)
+62 -39
View File
@@ -14,6 +14,15 @@ class CommitGenerator(AIService):
def __init__(self, config: Config):
"""Initialize commit generator."""
super().__init__(config)
# Read emoji preference from config (default: disabled)
self.use_emoji: bool = bool(
str(self.config.get("emoji", "false")).strip().lower() in [
"1",
"true",
"yes",
"on",
]
)
def generate_commit_message(
self, diff: str, temperature: Optional[float] = None
@@ -57,7 +66,7 @@ Output ONLY the commit message. Do not include any comments or explanations."""
{diff}
Identify the most relevant type, a concise scope, and the purpose of the change.
Output ONLY the commit message in the correct format (with emoji)."""
Output ONLY the commit message in the correct format{" with emoji" if self.use_emoji else " without any emoji"}."""
message = self.generate_completion(
system_prompt, user_prompt, temperature=temperature
@@ -86,25 +95,33 @@ Output ONLY the commit message in the correct format (with emoji)."""
else:
message = lines[0] if lines else "🔧 chore: update code"
if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
):
if message.startswith("feat"):
message = "✨ " + message
elif message.startswith("fix"):
message = "🐛 " + message
elif message.startswith("docs"):
message = "📚 " + message
elif message.startswith("style"):
message = "💅 " + message
elif message.startswith("refactor"):
message = "♻️ " + message
elif message.startswith("test"):
message = "✅ " + message
elif message.startswith("chore"):
message = "🔧 " + message
else:
message = "🔧 " + message # fallback
# Apply or remove emoji based on configuration
if self.use_emoji:
if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
):
if message.startswith("feat"):
message = "✨ " + message
elif message.startswith("fix"):
message = "🐛 " + message
elif message.startswith("docs"):
message = "📚 " + message
elif message.startswith("style"):
message = "💅 " + message
elif message.startswith("refactor"):
message = "♻️ " + message
elif message.startswith("test"):
message = "✅ " + message
elif message.startswith("chore"):
message = "🔧 " + message
else:
message = "🔧 " + message # fallback
else:
# Strip known emojis if present
for emoji in ["✨ ", "🐛 ", "📚 ", "💅 ", "♻️ ", "✅ ", "🔧 "]:
if message.startswith(emoji):
message = message[len(emoji) :]
break
return message
@@ -203,25 +220,31 @@ Output ONLY the commit message in the correct format (with emoji)."""
message = lines[0] if lines else "🔧 chore: update code"
# Ensure proper emoji prefix
if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
):
if message.startswith("feat"):
message = "✨ " + message
elif message.startswith("fix"):
message = "🐛 " + message
elif message.startswith("docs"):
message = "📚 " + message
elif message.startswith("style"):
message = "💅 " + message
elif message.startswith("refactor"):
message = "♻️ " + message
elif message.startswith("test"):
message = "✅ " + message
elif message.startswith("chore"):
message = "🔧 " + message
else:
message = "🔧 " + message # fallback
if self.use_emoji:
if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
):
if message.startswith("feat"):
message = "✨ " + message
elif message.startswith("fix"):
message = "🐛 " + message
elif message.startswith("docs"):
message = "📚 " + message
elif message.startswith("style"):
message = "💅 " + message
elif message.startswith("refactor"):
message = "♻️ " + message
elif message.startswith("test"):
message = "✅ " + message
elif message.startswith("chore"):
message = "🔧 " + message
else:
message = "🔧 " + message # fallback
else:
for emoji in ["✨ ", "🐛 ", "📚 ", "💅 ", "♻️ ", "✅ ", "🔧 "]:
if message.startswith(emoji):
message = message[len(emoji) :]
break
return message