Last active
March 11, 2024 13:57
-
-
Save valb-mig/8da59466a4923959927ae036e21b3e5f to your computer and use it in GitHub Desktop.
🪽 (Padrões de commit): Script em python para executar commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import subprocess | |
# Examples of commit types: | |
# init: Initial commit, used to mark the beginning of the project. | |
# feat: Addition of a new feature to the project. | |
# fix: Fixing a bug in the code. | |
# style: Changes related to code styling, such as formatting, spacing, etc. | |
# docs: Changes in the project's documentation. | |
# chore: Maintenance tasks, such as configurations, updates, etc. | |
# wait: Commit marking work in progress, not yet finalized. | |
# refactor: Code refactoring, without changing functionality. | |
# test: Addition or modification of tests in the code. | |
def show_options(): | |
print("Available commit options:") | |
print("init: Initial commit, used to mark the beginning of the project.") | |
print("feat: Addition of a new feature to the project.") | |
print("fix: Fixing a bug in the code.") | |
print("style: Changes related to code styling, such as formatting, spacing, etc.") | |
print("docs: Changes in the project's documentation.") | |
print("chore: Maintenance tasks, such as configurations, updates, etc.") | |
print("wait: Commit marking work in progress, not yet finalized.") | |
print("refactor: Code refactoring, without changing functionality.") | |
print("test: Addition or modification of tests in the code.") | |
def show_included_files(): | |
try: | |
status_output = subprocess.check_output(['git', 'diff', '--cached', '--name-only']) | |
print("\033[1;33mFiles included in the commit:\033[0m") | |
print("\033[1;31m" + status_output.decode('utf-8') + "\033[0m") | |
except subprocess.CalledProcessError as e: | |
print("An error occurred while getting file status:", e) | |
def main(): | |
terminal_params = sys.argv | |
if '-h' in terminal_params or '--help' in terminal_params: | |
show_options() | |
exit() | |
if len(terminal_params) < 3 or len(terminal_params[1]) <= 0 or len(terminal_params[2]) <= 0: | |
print("\033[1;31mMissing parameters\033[0m") | |
exit() | |
commit_type = terminal_params[1] | |
commit_text = ' '.join(terminal_params[2:]) | |
commit_message = "" | |
if commit_type == "init": | |
commit_message = ":tada:(init): " + commit_text | |
elif commit_type == "feat": | |
commit_message = ":sparkles:(feat): " + commit_text | |
elif commit_type == "fix": | |
commit_message = ":bug:(fix): " + commit_text | |
elif commit_type == "style": | |
commit_message = ":lipstick:(style): " + commit_text | |
elif commit_type == "docs": | |
commit_message = ":books:(docs): " + commit_text | |
elif commit_type == "chore": | |
commit_message = ":wrench:(chore): " + commit_text | |
elif commit_type == "wait": | |
commit_message = ":construction:(in progress): " + commit_text | |
elif commit_type == "refactor": | |
commit_message = ":recycle:(refactor): " + commit_text | |
elif commit_type == "test": | |
commit_message = ":test_tube:(test): " + commit_text | |
else: | |
print("Invalid commit type") | |
exit() | |
working_directory = os.getcwd() | |
show_included_files() | |
confirmation = input("Do you want to confirm the commit? (y/n): ").lower() | |
if confirmation == 'y': | |
try: | |
subprocess.run(['git', 'commit', '-m', commit_message], cwd=working_directory, check=True) | |
print("\033[1;32mCommit successful!\033[0m") | |
except subprocess.CalledProcessError as e: | |
print("An error occurred while committing:", e) | |
else: | |
print("\033[1;31mCommit canceled by the user.\033[0m") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment