The Auto-Commit Bot is a Python-based tool that automatically monitors a directory for changes, generates meaningful commit messages using the Google Gemini API, and commits the changes to a Git repository. It’s perfect for automating repetitive Git tasks and ensuring consistent commit messages.
- Real-Time File Monitoring: Watches a directory for changes (created, modified, or deleted files).
- Auto-Commit: Automatically stages and commits changes with a generated commit message.
- AI-Powered Commit Messages: Uses the Google Gemini API to generate concise and meaningful commit messages based on
git diff
. - Git Repository Management: Initializes a Git repository if one doesn’t exist in the directory.
- Customizable: Easily extendable to include additional features like auto-pushing to a remote repository.
- Python 3.7 or higher
- A Google Gemini API key (sign up here)
-
Clone the repository:
git clone https://github.com/suwi-lanji/auto-commit.git cd auto-commit
-
Install the required dependencies:
pip install -r requirements.txt
-
Set your Google Gemini API key as an environment variable:
export GEMINI_API_KEY="your-api-key"
-
Install the package locally:
pip install .
Run the Auto-Commit Bot on a directory:
auto-commit /path/to/your/directory
-
Repository Initialization:
- If the directory is not a Git repository, the bot initializes one.
-
File Monitoring:
- The bot monitors the directory for changes (created, modified, or deleted files).
-
Auto-Commit:
- When changes are detected:
- The bot stages all changes.
- Generates a commit message using the Google Gemini API.
- Commits the changes with the generated message.
- When changes are detected:
-
Logging:
- All actions (e.g., detected changes, generated commit messages, commits) are logged to the console.
/my-project/
├── file1.txt
├── file2.txt
auto-commit /my-project
-
Modify
file1.txt
:echo "New content" >> /my-project/file1.txt
-
The bot detects the change and outputs:
Modified: /my-project/file1.txt Staged all changes. Generated commit message: Updated file1.txt with new content. Committed changes with message: Updated file1.txt with new content.
-
Check the Git log:
git -C /my-project log --oneline
Output:
abc1234 Updated file1.txt with new content.
GEMINI_API_KEY
: Your Google Gemini API key.
directory
: The directory to monitor (required).--api-key
: The Google Gemini API key (optional if set as an environment variable).
Contributions are welcome! Here’s how you can contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature
- Commit your changes:
git commit -m "Add your feature"
- Push to the branch:
git push origin feature/your-feature
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Google Gemini API: For providing the AI model to generate commit messages.
- GitPython: For simplifying Git operations in Python.
- Watchdog: For monitoring file system changes.
If you have any questions or need further assistance, feel free to open an issue on the GitHub repository.