Skip to content

Commit

Permalink
feat: --emoji-disabled feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
AliYmn committed Apr 16, 2024
1 parent 9a605b3 commit 241a462
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ repos:
hooks:
- id: conventional-commits-check
stages: [commit-msg]
args: ["--emoji-disabled"] # Add this argument to disable emojis
```
2. Update the pre-commit hooks in your project:
Expand All @@ -103,4 +104,4 @@ pre-commit autoupdate
# Usage
Once the hook is added to your project, it will automatically run every time you create a commit. The hook will check the commit messages according to the Conventional Commits rules and add corresponding emojis. If a commit message does not follow the rules, the commit will be blocked.
Once the hook is added to your project, it will automatically run every time you create a commit. The hook will check the commit messages according to the Conventional Commits rules and add corresponding emojis. If a commit message does not follow the rules, the commit will be blocked.
2 changes: 1 addition & 1 deletion commits_check_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ additional_commands:

additional_emojis:
database: "🗃️"
design: "🎨"
design: "🎨"
17 changes: 11 additions & 6 deletions conventional_commits_check/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import argparse
import re
import sys
from typing import Dict
import yaml
import os

Expand Down Expand Up @@ -43,11 +42,14 @@ def load_custom_rules(config_file="commits_check_config.yaml"):
with open(config_path, "r") as file:
config_data = yaml.safe_load(file)

return config_data.get("additional_commands", {}), config_data.get("additional_emojis", {})
return config_data.get("additional_commands", {}), config_data.get(
"additional_emojis", {}
)

except FileNotFoundError:
print(
f"No such file or directory: '{config_path}'. Please make sure the config file is in the correct directory.")
f"💥 No such file or directory: '{config_path}'. Please make sure the config file is in the correct directory."
)
sys.exit(1)


Expand All @@ -60,6 +62,7 @@ def main():

parser = argparse.ArgumentParser()
parser.add_argument("commit_message_file")
parser.add_argument("--emoji-disabled", action="store_true", help="Disable emojis in commit messages")
args = parser.parse_args()

with open(args.commit_message_file, "r") as file:
Expand All @@ -72,17 +75,19 @@ def main():
break

if not commit_type:
print("Commit message does not follow Conventional Commits rules.")
print("💥 Commit message does not follow Conventional Commits rules.")
sys.exit(1)

emoji = EMOJIS.get(commit_type)

if emoji:
if emoji and not args.emoji_disabled:
new_commit_message = f"{emoji} {commit_message}"
with open(args.commit_message_file, "w") as file:
file.write(new_commit_message)

print("Commit message follows Conventional Commits rules and has been updated with an emoji.")
print(
"🎉 Commit message follows Conventional Commits rules and has been updated with an emoji."
)
sys.exit(0)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="conventional-commits-check",
version="1.0.4",
version="2.0.0",
description="A pre-commit hook to check Conventional Commits and add emojis.",
author="Ali Yaman",
packages=find_packages(),
Expand Down

0 comments on commit 241a462

Please sign in to comment.