π» Gitmoji Police: Enforce Emoji Rules in Commit Messages
Stop emoji chaos with this Python script that validates and snarks on your commit messages.
#!/usr/bin/env python3
"""
Gitmoji Police - Enforce sensible emoji usage in commit messages
"""
import re
import sys
# Valid emoji patterns with descriptions
EMOJI_RULES = {
r'π': 'Performance improvements only',
r'π': 'Bug fixes only',
r'β¨': 'New features only',
r'π': 'Major releases only',
r'π': 'Documentation updates only',
r'β»οΈ': 'Code refactoring only',
r'π§': 'Configuration changes only'
}
# Snarky feedback for violations
SNARKY_RESPONSES = [
"π for removing a console.log? Really?",
"π for merging your own branch? That's like throwing yourself a birthday party.",
"π for a typo fix? Save it for actual bugs.",
"β¨ for updating a comment? Not that shiny."
]
def validate_commit_message(message):
"""Validate commit message against emoji rules"""
violations = []
# Check if message contains any emoji
emoji_pattern = r'[\U0001F300-\U0001F9FF]'
emojis_found = re.findall(emoji_pattern, message)
if not emojis_found:
return True, "No emojis found - boring but acceptable"
# Validate each emoji against rules
for emoji in emojis_found:
if emoji in EMOJI_RULES:
violations.append(f"{emoji}: {EMOJI_RULES[emoji]}")
if violations:
feedback = "\n".join(violations)
snark = "\n㪠" + random.choice(SNARKY_RESPONSES)
return False, feedback + snark
return True, "All emojis pass the vibe check!"
# Usage example
if __name__ == "__main__":
commit_msg = "π Removed console.log statement"
is_valid, feedback = validate_commit_message(commit_msg)
if not is_valid:
print("β Commit rejected!")
print(feedback)
sys.exit(1)
else:
print("β
Commit accepted!")
print(feedback)
The Problem: When Emojis Become More Important Than Code
Let's be honest: somewhere along the line, we collectively decided that commit messages needed personality. Not clarity, not usefulness, not actual information about what changedβpersonality. So we started slapping emojis on everything like we're texting our BFF about weekend plans instead of documenting software changes that might need to be debugged at 3 AM.
The result? Git logs that read like hieroglyphics interpreted by a particularly enthusiastic toddler. "π Added caching" could mean anything from "I implemented Redis" to "I removed a console.log statement." "π Fixed bug" might refer to a critical security vulnerability or that time you spelled 'function' as 'funtion.' And don't get me started on the π emojiβapparently every single merge deserves a celebration, even when you're just merging your own feature branch that you created 20 minutes ago.
Worst of all, we're wasting actual development time on this nonsense. I've seen developers spend longer choosing between π οΈ and π§ than they spent writing the actual code. We've created a whole new dimension of bike-shedding, except instead of arguing about programming languages, we're debating whether database migrations deserve a π or a π¦. It's absurd, it's unprofessional, and it's making our version control history about as useful as a chocolate teapot.
The Solution: Introducing Gitmoji Police
I built Gitmoji Police because someone had to bring order to this emoji anarchy. This isn't about being the fun police (though the name suggests otherwise)βit's about restoring sanity to our commit messages. The tool validates emoji usage against configurable rules, ensuring that your π actually accompanies performance improvements and your π is reserved for actual bugs, not your typo fixes.
Here's how it works at a high level: Gitmoji Police hooks into your git workflow and analyzes commit messages before they're finalized. It checks the emoji against your team's configured rules (which you can customize to match your project's actual needs, not just arbitrary preferences). It can even suggest appropriate emojis based on the code changes detected via git diffβbecause sometimes you genuinely forget which emoji goes with database migrations (it's ποΈ, obviously).
The best part? When you violate the conventions, Gitmoji Police doesn't just reject your commitβit generates snarky, educational rejection messages that actually teach you why your emoji choice was wrong. "β This π emoji is reserved for performance improvements, not your README update" is both hilarious and actually helpful. It's like having a particularly sarcastic senior developer looking over your shoulder, except this one works 24/7 and doesn't need coffee breaks.
How to Use Gitmoji Police
Getting started is simpler than choosing between π¨ and β»οΈ for your CSS refactor (spoiler: it's β»οΈ if you're actually recycling/reusing code, π¨ if you're just making it prettier). First, install the package:
npm install -g emoji-commit-validator
# or
pip install emoji-commit-validator
# or check the GitHub for other installation methodsThen, set up your configuration file. Here's a basic example of what the rule configuration looks like, taken straight from the Gitmoji Police source code:
{
"rules": [
{
"emoji": "π",
"required_keywords": ["performance", "optimize", "speed"],
"forbidden_keywords": ["readme", "typo", "comment"],
"rejection_message": "π is for performance improvements only"
},
{
"emoji": "π",
"required_keywords": ["fix", "bug", "error"],
"min_changes": 3,
"rejection_message": "π requires actual bug fixes, not minor tweaks"
}
]
}Check out the full source code on GitHub for more advanced configuration options and examples. Once configured, Gitmoji Police integrates with your git hooks to automatically validate commits. No more emoji anarchyβjust clean, meaningful commit messages that your future self (and your teammates) will actually appreciate.
Key Features That Actually Matter
- Configurable Validation Rules: Define exactly which emojis can be used with which types of changes. Want to reserve π for performance improvements only? Done. Want to ban π from all commit messages because celebrations should be earned? You're the boss.
- Intelligent Suggestions: Based on git diff analysis, Gitmoji Police can suggest appropriate emojis when you're stuck. Added new dependencies? It might suggest π¦. Fixed a security issue? π would be appropriate.
- Snarky But Educational Rejections: When you violate the rules, you get feedback that's both funny and actually helpful. "β This π emoji is reserved for actual bugs, not your typo fix" teaches proper usage while making you chuckle.
- Git Hook Integration: Seamlessly integrates with pre-commit or commit-msg hooks, so validation happens automatically without disrupting your workflow.
- Team Configuration Sharing: Share a single configuration file across your team to ensure consistency. No more debating emoji meanings in standup meetings.
Conclusion: Bring Order to Your Commit Chaos
Gitmoji Police might seem like a joke toolβand let's be honest, the problem it solves is pretty ridiculousβbut it actually delivers real value. By enforcing sensible emoji conventions, it makes your git logs more readable, more professional, and actually useful for understanding what changed and why. No more deciphering emoji hieroglyphics at 2 AM when production is down.
The tool is free, open source, and available right now on GitHub. Give it a try, configure it for your team's needs, and start committing with confidence that your π actually means something. Your future self (and anyone else who needs to read your commit messages) will thank you.
Try it out: https://github.com/BoopyCode/emoji-commit-validator
Remember: just because you can put a π¦ emoji in every commit message doesn't mean you should. Some things are magical, but your middleware refactor probably isn't one of them.
Quick Summary
- What: Gitmoji Police validates emoji usage in commit messages against configurable rules, ensuring your git logs maintain some semblance of professionalism.
π¬ Discussion
Add a Comment