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
+35 -3

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)
+24 -1
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,6 +95,8 @@ 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"
# Apply or remove emoji based on configuration
if self.use_emoji:
if not any( if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"] emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
): ):
@@ -105,6 +116,12 @@ Output ONLY the commit message in the correct format (with emoji)."""
message = "🔧 " + message message = "🔧 " + message
else: else:
message = "🔧 " + message # fallback 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,6 +220,7 @@ 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 self.use_emoji:
if not any( if not any(
emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"] emoji in message for emoji in ["✨", "🐛", "📚", "💅", "♻️", "✅", "🔧"]
): ):
@@ -222,6 +240,11 @@ Output ONLY the commit message in the correct format (with emoji)."""
message = "🔧 " + message message = "🔧 " + message
else: else:
message = "🔧 " + message # fallback message = "🔧 " + message # fallback
else:
for emoji in ["✨ ", "🐛 ", "📚 ", "💅 ", "♻️ ", "✅ ", "🔧 "]:
if message.startswith(emoji):
message = message[len(emoji) :]
break
return message return message