Skip to content

Instantly share code, notes, and snippets.

@Ambro17
Created May 26, 2020 23:10
Show Gist options
  • Save Ambro17/fc56167d95783f6b91385006c6f05db5 to your computer and use it in GitHub Desktop.
Save Ambro17/fc56167d95783f6b91385006c6f05db5 to your computer and use it in GitHub Desktop.
Auto Git Emoji
#!/usr/bin/python3.6
"""
Loosely based on gitmoji https://gitmoji.carloscuesta.me/
WIP: 🚧
Meant for work in progress. Incomplete or still an idea
NEW: ✨
New functionality that is working. Meant as a checkpoint
FIX: πŸ”§
Minor code changes/ Refactors that are steps before a NEW feature
BUG: 🐞
Bugfix, it explais itself
ART: 🎨
Cosmetic changes based on linting. (Docstrings, typos, bad variable names, etc)
TDD: βœ”οΈ
Test related changes. Create/Delete/Update tests
merge: πŸ”„
Merge related changes
docs: πŸ“š
Add documentation
Any combination of this three structures will work, case insensitive
* Opening -> [ ( { :
* Content -> wip new fix bug art tdd
* Closing -> ] ) } :
"""
import sys
import re
# Will match things like [wip: too, but anyway ...
# who would want to see that instead of a beautiful emoji?
full_regex = re.compile(
r'([{|:|\[|\(](wip|new|fix|bug|art|tdd|doc|merge)[}|:|\]|\)])',
re.IGNORECASE,
)
replacement_icons = {
'wip': '🚧',
'new': '✨',
'fix': 'πŸ”§',
'bug': '🐞',
'art': '🎨',
'tdd': 'βœ”οΈ',
'merge': 'πŸ”„',
'doc': 'πŸ“š',
}
def insert_emojis(commit_file):
with open(commit_file, 'r') as f:
commit_message = f.read()
for full_match, emoji_str in set(full_regex.findall(commit_message)):
commit_message = commit_message.replace(
full_match,
replacement_icons[emoji_str.lower()],
)
with open(commit_file, 'w') as f:
f.write(commit_message)
def main():
commit_file = sys.argv[1]
with open(commit_file, 'r') as f:
backup = f.read()
try:
insert_emojis(commit_file)
except Exception:
print("Could not place emojis in commit message")
with open(commit_file, 'w') as f:
f.write(backup)
finally:
sys.exit(0)
main()
@eduzen
Copy link

eduzen commented Nov 16, 2021

thanks a lot!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment