mdeloughry / gcm-gen
Git Commit Message Generator
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- nunomaduro/termwind: ^1.15
- dev-main
- v0.007
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.3a
- v0.0.2
- 0.0.1
- dev-feature/resource-dir
- dev-feature/6-refactor-suggestion-handle-potential-failures-when-writing-the-config-file
- dev-4-refactor-suggestion-inconsistent-retrieval-of-home-directory
- dev-bugfix/fix-missing-config-generation
- dev-feature/command-output
This package is auto-updated.
Last update: 2024-12-12 18:42:19 UTC
README
GCM-Gen is a CLI tool that generates meaningful commit messages by analysing your git changes. It uses AI to understand your code changes and generate appropriate commit messages. Supports both ChatGPT and Ollama for AI processing.
Features
- 🤖 AI-powered commit message generation (ChatGPT or Ollama)
- ⚡ Quick and easy to use
- 🛠️ Configurable prompts and settings
- 📝 Direct git commit integration with branch-based commit types
- 🎨 Beautiful terminal UI
Choosing an LLM Provider
GCM-Gen supports two AI providers, each with their own advantages:
ChatGPT (Recommended for Best Results)
- ✅ Superior commit message quality
- ✅ Faster processing
- ✅ Lower system requirements
- ❌ Requires API key
- ❌ Sends code diffs to OpenAI servers
- ❌ Usage costs (pay per API call)
Ollama (Recommended for Privacy/Offline Use)
- ✅ Completely free to use
- ✅ Runs 100% locally
- ✅ No data leaves your machine
- ❌ Requires significant system resources
- ❌ Slower processing time
- ❌ May produce less consistent results
Choose ChatGPT if you want the best quality commit messages and don't mind the API costs. Choose Ollama if you need to keep your code private or want a free, offline solution.
Requirements
Core Requirements
- PHP 8.1 or higher
- Composer
- Git
AI Provider Requirements
Option 1: ChatGPT
- OpenAI API Key
- Sign up at OpenAI Platform
- Create an API key at API Keys
- Add the API key to your configuration file
Option 2: Ollama
- Install Ollama
- Visit Ollama.ai to download and install
- Follow the installation instructions for your operating system
- Start the Ollama service:
ollama serve
- Pull the required model:
ollama pull llama3.2
Installation
Global Installation
composer global require mdeloughry/gcm-gen
Make sure your global Composer bin directory is in your system's PATH.
Usage
# Generate a commit message gcm-gen g # Generate and commit in one go gcm-gen c # Show current configuration gcm-gen config # Edit configuration gcm-gen config --edit
Configuration
On first run, GCM-Gen will create a configuration file at ~/.config/gcm-gen.config.php
. You can edit this file directly or use:
gcm-gen config --edit
Configuration Options
The configuration file supports both ChatGPT and Ollama providers. Here's a complete example:
return [ 'provider' => 'chatgpt', // or 'ollama' 'ignore_files' => [ 'vendor', 'node_modules', 'package-lock.json', 'yarn.lock', 'composer.lock', 'dist', 'build', 'public', 'storage', ], 'ollama' => [ 'model' => 'llama3.2', // Default model ], 'chatgpt' => [ 'model' => 'gpt-4', // Default model 'api_key' => 'your-api-key-here', ], 'prompt' => <<<EOL Generate a git commit message based on the following rules: 1. First line: - Use imperative mood (Add not Added) - Max 50 characters - Format: [type] - [ticket] [description] - [ticket] is optional and can be built from the branch name look for the pattern '/(?:#(\d+)|([A-Z]+-\d+))/i' - [type] from branch patterns using emojis only (no branch pattern match): feature/* → ✨ bugfix/hotfix/* → 🐛 release/* → 🔖 default → 🤖 2. Optional body (if changes are complex): - Leave one blank line after subject - Create a new line at 72 characters - Explain the type of change in the first line - Explain what and why, not how - Add BREAKING CHANGE: for breaking changes EOL, ];
Configuration Breakdown
provider
: Choose between 'chatgpt' or 'ollama'ignore_files
: List of files and directories to exclude from the git diff analysisollama
: Ollama-specific settingsmodel
: The Ollama model to use (default: llama3.2)
chatgpt
: ChatGPT-specific settingsmodel
: The GPT model to use (default: gpt-4)api_key
: Your OpenAI API key
prompt
: The template used to generate commit messages, supporting:- Automatic emoji type based on branch name
- Ticket number extraction from branch names
- Conventional commit message formatting
Development Setup
- Clone the repository:
git clone https://github.com/mdeloughry/gcm-gen.git
cd gcm-gen
- Install dependencies:
composer install
- Set up your environment:
- Copy
.env.example
to.env
- Add your OpenAI API key to
.env
- Run tests:
composer test
Development Requirements
- PHP 8.1 or higher
- Composer
- OpenAI API key or Ollama installed locally
- Git
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any problems or have suggestions, please open an issue.