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