This project uses a pre-commit hook to analyze staged files with the Gemini AI model. It checks for potential bugs, typos, debug statements, and areas for improvement.
- Python 3.6+
- Git
-
Clone the repository:
git clone <repository-url> cd <repository-name>
-
Set up a Python virtual environment:
It's recommended to use a virtual environment to manage project dependencies.
python3 -m venv .venv
-
Activate the virtual environment:
- On macOS/Linux:
source .venv/bin/activate - On Windows (Command Prompt):
.venv\Scripts\activate.bat
- On Windows (PowerShell):
.venv\Scripts\Activate.ps1
- On macOS/Linux:
-
Install project dependencies:
pip install -r requirements.txt
-
Install pre-commit and set up the hooks:
This project uses
pre-committo manage and run its Git hooks.First, install
pre-commit(it will be installed into your active virtual environment):pip install pre-commit
Then, from the root of this repository, install the Git hooks:
pre-commit install
This command sets up the Git hooks in your local
.git/hooksdirectory, pointing them to thepre-commitframework. The hooks will then run automatically ongit commit. -
Set your Gemini API Key:
The script requires a Gemini API key to be set as an environment variable.
export GEMINI_API_KEY="YOUR_API_KEY"
To make this permanent, add it to your shell's profile file (e.g.,
~/.bashrc,~/.zshrc).
Once installed, the pre-commit hook will run automatically every time you run git commit. It will analyze the staged files and report any issues found by the Gemini model.
- If the check passes, the commit will proceed.
- If the check fails, the commit will be aborted, and you will see a list of issues to fix.
To skip the pre-commit check for a specific commit, use the --no-verify flag:
git commit -m "Your message" --no-verifyTo see the full request and response from the Gemini API, set the GEMINI_CHECK_DEBUG environment variable to true:
export GEMINI_CHECK_DEBUG=true