Skip to main content

AI-powered Git commit message generator that automatically creates conventional commit messages using Groq, OpenRouter, or Cohere APIs. Source: https://github.com/Joshi-e8/ai-commit-generator.git

Project description

๐Ÿค– AI-Powered Git Commit Message Generator

PyPI version Python Support License: MIT Downloads

Automatically generate conventional commit messages using AI - No backend/frontend required!

This tool works as a Git pre-commit hook that analyzes your staged changes and generates professional commit messages using AI APIs (Groq, OpenRouter, Cohere).


๐Ÿš€ Quick Start (2 minutes)

1. Install the Package

# Install from PyPI (recommended)
pip install smart-commits-ai

# Or install from source
pip install git+https://github.com/Joshi-e8/ai-commit-generator.git

2. Get API Key (Free)

3. Install in Your Project

# Go to your project
cd /path/to/your/project

# Install the Git hook
smart-commits-ai install

# Add your API key
echo "GROQ_API_KEY=your_key_here" >> .env

4. Use It

# Normal Git workflow - AI handles the message!
git add src/components/Button.js
git commit  # โœจ AI generates: "feat(ui): add Button component with hover effects"

๐Ÿ“ฆ Installation Methods

Method 1: PyPI (Recommended)

pip install smart-commits-ai

Method 2: From Source

git clone https://github.com/your-org/ai-commit-generator.git
cd ai-commit-generator
pip install -e .

Method 3: Legacy Bash Script

For the original bash-based installation, see LEGACY.md.


โœจ Features

  • ๐Ÿค– AI-Powered: Uses Groq, OpenRouter, or Cohere APIs
  • ๐Ÿ“ Conventional Commits: Automatic type(scope): description format
  • โšก Fast: < 2 second response time with Groq
  • ๐Ÿ”ง Configurable: Customize prompts, models, and scopes
  • ๐Ÿ›ก๏ธ Secure: Only staged changes sent to AI, no data storage
  • ๐Ÿ”„ Fallback: Works even if AI fails
  • ๐Ÿ Python Package: Easy installation and distribution
  • ๐Ÿงช Testable: Comprehensive test suite and type hints
  • ๐ŸŽจ Rich CLI: Beautiful command-line interface with colors

๐ŸŽฏ Example Output

Before:

git commit -m "fix"
git commit -m "update"
git commit -m "changes"

After:

feat(auth): implement JWT token refresh mechanism
fix(api): resolve race condition in user registration  
docs: update README with installation instructions
refactor(utils): optimize date formatting functions

๐Ÿ“ Project Structure

ai-commit-generator/
โ”œโ”€โ”€ README.md                           # This file
โ”œโ”€โ”€ TEAM_SETUP_GUIDE.md                # Detailed team documentation
โ”œโ”€โ”€ pyproject.toml                     # Python package configuration
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ ai_commit_generator/
โ”‚       โ”œโ”€โ”€ __init__.py                # Package initialization
โ”‚       โ”œโ”€โ”€ cli.py                     # Command-line interface
โ”‚       โ”œโ”€โ”€ core.py                    # Main commit generation logic
โ”‚       โ”œโ”€โ”€ config.py                  # Configuration management
โ”‚       โ”œโ”€โ”€ api_clients.py             # AI API clients
โ”‚       โ””โ”€โ”€ git_hook.py                # Git hook management
โ”œโ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ .commitgen.yml                 # Configuration template
โ”‚   โ””โ”€โ”€ .env.example                   # Environment template
โ”œโ”€โ”€ tests/                             # Test suite
โ”œโ”€โ”€ examples/                          # Usage examples
โ””โ”€โ”€ legacy/                            # Original bash scripts
    โ”œโ”€โ”€ install_hook.sh                # Legacy installer
    โ””โ”€โ”€ hooks/
        โ””โ”€โ”€ prepare-commit-msg         # Legacy hook script

๐Ÿ–ฅ๏ธ CLI Commands

Install Hook

# Install Git hook in current repository
smart-commits-ai install

# Install with configuration files
smart-commits-ai install --config

# Force overwrite existing hook
smart-commits-ai install --force

Manage Installation

# Check installation status
smart-commits-ai status

# Test with current staged changes
smart-commits-ai test

# Uninstall hook
smart-commits-ai uninstall

Generate Messages

# Generate message for staged changes
smart-commits-ai generate

# Generate without writing to file (dry run)
smart-commits-ai generate --dry-run

# Generate and save to specific file
smart-commits-ai generate --output commit-msg.txt

Configuration

# Show current configuration
smart-commits-ai config --show

# Validate configuration
smart-commits-ai config --validate

๐Ÿ”ง Configuration

Basic Setup (.env)

# Choose one provider
GROQ_API_KEY=gsk_your_key_here
# OPENROUTER_API_KEY=sk-or-your_key_here
# COHERE_API_KEY=your_cohere_key_here

Advanced Setup (.commitgen.yml)

api:
  provider: groq
  
commit:
  max_chars: 72
  types: [feat, fix, docs, style, refactor, test, chore]
  scopes: [api, ui, auth, db, config]
  
prompt:
  template: |
    Generate a conventional commit message for:
    {{diff}}

๐Ÿข Team Deployment

Option 1: Shared Network Drive

# Copy to shared location
cp -r ai-commit-generator /shared/tools/

# Team members install from shared location
/shared/tools/ai-commit-generator/install_hook.sh

Option 2: Internal Git Repository

# Create internal repo
git init ai-commit-generator
git add .
git commit -m "feat: add AI commit message generator"
git remote add origin https://github.com/your-org/ai-commit-generator.git
git push -u origin main

# Team members clone and install
git clone https://github.com/your-org/ai-commit-generator.git
cd your-project
../ai-commit-generator/install_hook.sh

Option 3: Package Distribution

# Create distributable package
tar -czf ai-commit-generator.tar.gz ai-commit-generator/

# Team members download and extract
curl -sSL https://your-server/ai-commit-generator.tar.gz | tar -xz
./ai-commit-generator/install_hook.sh

๐Ÿ› ๏ธ Advanced Usage

Custom Prompts

prompt:
  template: |
    You are a senior developer. Generate a commit message for:
    
    {{diff}}
    
    Requirements:
    - Use conventional commits
    - Be specific about business impact
    - Maximum {{max_chars}} characters

Multiple Models

# Fast and efficient
GROQ_MODEL=llama3-8b-8192

# More detailed
GROQ_MODEL=llama3-70b-8192

# Creative
GROQ_MODEL=mixtral-8x7b-32768

Debug Mode

DEBUG_ENABLED=true
tail -f .commitgen.log

๐Ÿšจ Troubleshooting

Issue Solution
"API key not found" Check .env file, ensure correct variable is set
"jq: command not found" Install jq: brew install jq or apt install jq
"Rate limit exceeded" Wait 1 minute or switch to different provider
"Hook not working" Reinstall: ./install_hook.sh

๐Ÿ“Š Provider Comparison

Provider Speed Cost Models Best For
Groq โšก Very Fast ๐Ÿ†“ Free Llama 3, Mixtral Teams, Daily Use
OpenRouter ๐ŸŒ Medium ๐Ÿ’ฐ Paid Claude, GPT-4 Premium Quality
Cohere โš–๏ธ Fast ๐Ÿ†“ Free Tier Command-R Enterprise

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'feat: add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

๐Ÿ“„ License

MIT License - see LICENSE file for details.


๐Ÿ™ Acknowledgments


Transform your team's commit messages today! ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smart_commits_ai-1.0.1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smart_commits_ai-1.0.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file smart_commits_ai-1.0.1.tar.gz.

File metadata

  • Download URL: smart_commits_ai-1.0.1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for smart_commits_ai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5db3d75126b70ecad4f8929ce229e8ad00122ab5e384c64f3336a41de5748938
MD5 c919e7fd992bfb703581b731e3e4ce29
BLAKE2b-256 0517d1539e7597e10ca770277f838dd85b4a1383a0663396febcc82078ebc5c3

See more details on using hashes here.

File details

Details for the file smart_commits_ai-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for smart_commits_ai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa181765a397cbfe61d7791e1077c08bb0613f8582a89ef16f95ef735d6b3333
MD5 cce1ed56918ed328cfeb890caaf6a010
BLAKE2b-256 df6ee857e7e8f86a4eec6600f1f3d923a74a196903abfe78c65ead1ed4a6fa82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page