├── rev_commit ├── __init__.py ├── config.py ├── rev_commit.py └── commit_generator.py ├── requirements.txt ├── setup.py ├── install.sh ├── README.md └── .gitignore /rev_commit/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | openai 2 | rich 3 | python-dotenv -------------------------------------------------------------------------------- /rev_commit/config.py: -------------------------------------------------------------------------------- 1 | GITHUB_TOKEN = "github_pat_..." 2 | ENDPOINT = "https://models.inference.ai.azure.com" 3 | MODEL_NAME = "gpt-4o" 4 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name="rev-commit", 5 | version="0.1", 6 | packages=find_packages(), 7 | install_requires=[ 8 | "openai", 9 | "rich", 10 | "python-dotenv" 11 | ], 12 | entry_points={ 13 | "console_scripts": [ 14 | "rev-commit=rev_commit.rev_commit:main", 15 | ], 16 | }, 17 | ) 18 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | install() { 4 | echo "Installing rev-commit..." 5 | pip3 install . 6 | echo "Installation complete." 7 | } 8 | uninstall() { 9 | echo "Uninstalling rev-commit..." 10 | pip3 uninstall -y rev-commit 11 | echo "Uninstallation complete." 12 | } 13 | case "$1" in 14 | install) 15 | install 16 | ;; 17 | uninstall) 18 | uninstall 19 | ;; 20 | *) 21 | echo "Usage: $0 {install|uninstall}" 22 | exit 1 23 | ;; 24 | esac -------------------------------------------------------------------------------- /rev_commit/rev_commit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import readline # noqa 4 | from rich.console import Console 5 | from rev_commit.commit_generator import generate_commit_message 6 | 7 | 8 | console = Console() 9 | 10 | 11 | def main(): 12 | try: 13 | console.print("[bold green]Enter the changes description:[/bold green]") # noqa 14 | changes = input() 15 | console.print(f"[bold green]Generating commit message...[/bold green]") # noqa 16 | changes_description = "\n".join(changes) 17 | commit_message = generate_commit_message(changes_description) 18 | console.print( 19 | f"[bold green]Generated Commit Message:[/bold green] " 20 | f"{commit_message}" 21 | ) 22 | except Exception as e: 23 | console.print(f"[bold red]Error:[/bold red] {str(e)}") 24 | 25 | 26 | if __name__ == "__main__": 27 | main() 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rev-commit 2 | 3 | `rev-commit` is a tool to generate commit messages using OpenAI's GPT-4 model. It helps you create meaningful and emoji-rich commit messages based on the description of changes you provide. 4 | 5 | ## Installation 6 | 7 | To install `rev-commit`, run the following command: 8 | 9 | ```sh 10 | ./install.sh install 11 | ``` 12 | 13 | ## Configuration 14 | 15 | Before using `rev-commit`, you need to configure your GitHub access token. Open the `rev_commit/config.py` file and replace the placeholder with your actual GitHub access token: 16 | 17 | ```python 18 | GITHUB_TOKEN = "your_github_access_token_here" 19 | ENDPOINT = "https://models.inference.ai.azure.com" 20 | MODEL_NAME = "gpt-4o" 21 | ``` 22 | 23 | ## Usage 24 | 25 | To generate a commit message, run the following command: 26 | 27 | ```sh 28 | rev-commit 29 | ``` 30 | 31 | You will be prompted to enter the description of changes. End the input with two consecutive empty lines to generate the commit message. 32 | 33 | ## Uninstallation 34 | 35 | To uninstall `rev-commit`, run the following command: 36 | 37 | ```sh 38 | pip uninstall rev-commit 39 | ``` 40 | or 41 | ```sh 42 | ./install.sh uninstall 43 | ``` -------------------------------------------------------------------------------- /rev_commit/commit_generator.py: -------------------------------------------------------------------------------- 1 | from openai import OpenAI 2 | from rev_commit.config import GITHUB_TOKEN, ENDPOINT, MODEL_NAME 3 | 4 | client = OpenAI( 5 | base_url=ENDPOINT, 6 | api_key=GITHUB_TOKEN, 7 | ) 8 | 9 | 10 | def generate_commit_message(changes_description): 11 | try: 12 | response = client.chat.completions.create( 13 | messages=[ 14 | { 15 | "role": "system", 16 | "content": ( 17 | "You are a helpful assistant for generating commit names." # noqa 18 | ), 19 | }, 20 | { 21 | "role": "user", 22 | "content": ( 23 | f"Generate a commit message using emoji (git emoji) for the following " # noqa 24 | f"changes: {changes_description}" 25 | ), 26 | }, 27 | ], 28 | temperature=1.0, 29 | top_p=1.0, 30 | max_tokens=100, 31 | model=MODEL_NAME, 32 | ) 33 | return response.choices[0].message.content.strip() 34 | except Exception as e: 35 | raise RuntimeError(f"Failed to generate commit message: {str(e)}") 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # celery beat schedule file 88 | celerybeat-schedule 89 | 90 | # dotenv 91 | .env 92 | .env.* 93 | 94 | # virtualenv 95 | venv/ 96 | ENV/ 97 | env/ 98 | env.bak/ 99 | venv.bak/ 100 | 101 | # Spyder project settings 102 | .spyderproject 103 | .spyproject 104 | 105 | # Rope project settings 106 | .ropeproject 107 | 108 | # mkdocs documentation 109 | /site 110 | 111 | # mypy 112 | .mypy_cache/ 113 | .dmypy.json 114 | dmypy.json 115 | 116 | # Pyre type checker 117 | .pyre/ 118 | 119 | # VS Code 120 | .vscode/ --------------------------------------------------------------------------------