diff --git a/commit.py b/commit.py new file mode 100644 index 0000000..86c11d7 --- /dev/null +++ b/commit.py @@ -0,0 +1,108 @@ +# Author : Eshan Roy +# Author URL : https://eshanized.github.io + +# NOTE: Run at your own risk. + +import os +import subprocess + +def commit_with_conventional_message(message, branch): + # Check if the commit message is conventional + if not is_conventional(message): + print("Error: Commit message is not conventional") + return + + # Add all changes + subprocess.run(["git", "add", "."]) + + # Commit with the conventional message + subprocess.run(["git", "commit", "-m", message]) + + # Push to GitHub + subprocess.run(["git", "push", "origin", branch]) + +def pull_from_github(branch): + # Pull from GitHub + subprocess.run(["git", "pull", "origin", branch]) + +def is_conventional(message): + # Check if the commit message is conventional + conventional_types = [ + "build", + "chore", + "ci", + "docs", + "feat", + "fix", + "perf", + "refactor", + "revert", + "style", + "test", + ] + for type in conventional_types: + if message.startswith(f"{commit_emojis[type]} {type}:") or message.startswith(f"{commit_emojis[type]} {type}("): + return True + return False + +# Get the conventional commit message type from the user +print("Select a conventional commit message type:") +print("1. feat (new feature) ๐ŸŽ‰") +print("2. fix (bug fix) ๐Ÿ”ง") +print("3. perf (performance improvement) โšก๏ธ") +print("4. refactor (code refactoring) ๐Ÿ’ก") +print("5. style (code style change) ๐Ÿ’„") +print("6. test (new test) ๐Ÿงช") +print("7. docs (documentation change) ๐Ÿ“š") +print("8. build (build process change) ๐Ÿ—๏ธ") +print("9. chore (miscellaneous task) ๐Ÿงน") +print("10. revert (revert previous commit) ๐Ÿšจ") + +option = int(input("Enter the number of your chosen option: ")) + +commit_types = [ + "feat", + "fix", + "perf", + "refactor", + "style", + "test", + "docs", + "build", + "chore", + "revert" + ] +commit_type = commit_types[option - 1] + +commit_emojis = { + "feat": "๐ŸŽ‰", + "fix": "๐Ÿ”ง", + "perf": "โšก๏ธ", + "refactor": "๐Ÿ’ก", + "style": "๐Ÿ’„", + "test": "๐Ÿงช", + "docs": "๐Ÿ“š", + "build": "๐Ÿ—๏ธ", + "chore": "๐Ÿงน", + "revert": "๐Ÿšจ", + "ci": "๐Ÿค–" # added ci key +} + +# Get the scope and description from the user +scope = input("Enter the scope (optional): ") +description = input("Enter the description: ") + +# Get the branch name from the user +branch = "master" # or "main", "development" + +# Construct the conventional commit message +if scope: + message = f"{commit_emojis[commit_type]} {commit_type}({scope}): {description}" +else: + message = f"{commit_emojis[commit_type]} {commit_type}: {description}" + +# Commit with the conventional message +commit_with_conventional_message(message, branch) + +# Pull from GitHub +pull_from_github(branch) \ No newline at end of file