byron / ai-git-automation
AI-powered Git automation for commit messages and PR summaries
Requires
- php: ^8.2.0
- ext-sodium: *
- guzzlehttp/guzzle: ^7.8
- illuminate/console: ^10.0|^11.0
- illuminate/http: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.18.3
- mockery/mockery: ^1.6.12
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^3.7.1
This package is auto-updated.
Last update: 2025-05-28 13:07:57 UTC
README
A Laravel package that automates commit message generation and PR summaries using AI (OpenAI or Claude). This package helps developers save time and maintain consistent documentation by generating meaningful commit messages and pull request descriptions.
Installation
You can install the package via composer:
composer require byron/ai-git-automation
The package will automatically register itself using Laravel's package discovery.
Configuration
Publish the configuration file:
php artisan vendor:publish --provider="Byron\AiGit\AiGitServiceProvider"
This will create a config/ai-git.php
configuration file. Add the following variables to your .env
file:
# Choose your AI provider (openai or claude) AI_PROVIDER=openai # OpenAI Configuration OPENAI_API_KEY=your-openai-api-key-here OPENAI_MODEL=gpt-4-turbo-preview OPENAI_TEMPERATURE=0.7 OPENAI_MAX_TOKENS=500 # Claude Configuration (if using Claude) CLAUDE_API_KEY=your-claude-api-key-here CLAUDE_MODEL=claude-3-opus-20240229 CLAUDE_TEMPERATURE=0.7 CLAUDE_MAX_TOKENS=500
Usage
Generating Commit Messages
# If using Laravel directly php artisan ai:commit # If using Laravel Sail sail artisan ai:commit --working-dir=/var/www/html
Options:
--m|message
: Manually specify a commit message--working-dir
: Specify the working directory (required when using Laravel Sail)
The command will:
- Check if there are staged changes
- Generate a commit message using AI based on the diff
- Show you the message and ask for confirmation
- Allow you to edit the message if needed
- Commit the changes with the approved message
Using with Laravel Sail
When using Laravel Sail, you need to specify the working directory because the command runs inside the Docker container. The working directory should be set to /var/www/html
which is the default Laravel Sail project directory:
# Generate commit message sail artisan ai:commit --working-dir=/var/www/html # Generate PR summary sail artisan ai:pr-summary --working-dir=/var/www/html [base] [head]
Generating PR Summaries
# If using Laravel directly php artisan ai:pr-summary [base] [head] # If using Laravel Sail sail artisan ai:pr-summary --working-dir=/var/www/html [base] [head]
Arguments:
base
: Base branch (default: current branch)head
: Head branch (default: current branch)
Options:
--main
: Generate a summary for merging to main branch--copy
: Copy the summary to clipboard--output
: Output file path to save the summary--working-dir
: Specify the working directory (required when using Laravel Sail)
GitHub Action Integration
To automatically generate PR descriptions, create .github/workflows/pr-description.yml
:
name: Generate PR Description on: pull_request: types: [opened, reopened] branches: [dev, main] jobs: generate-description: runs-on: ubuntu-latest if: github.event.pull_request.body == '' steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' - name: Install Dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Generate PR Description env: AI_PROVIDER: ${{ secrets.AI_PROVIDER || 'openai' }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} CLAUDE_API_KEY: ${{ secrets.CLAUDE_API_KEY }} run: php artisan ai:pr-summary ${{ github.event.pull_request.base.ref }} ${{ github.event.pull_request.head.ref }} --main --output=pr-description.txt - name: Update PR Description uses: actions/github-script@v6 with: script: | const fs = require('fs'); const description = fs.readFileSync('pr-description.txt', 'utf8'); await github.rest.pulls.update({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, body: description });
Add these secrets to your repository:
AI_PROVIDER
: Your chosen AI provider (openai or claude)OPENAI_API_KEY
: Your OpenAI API key (if using OpenAI)CLAUDE_API_KEY
: Your Claude API key (if using Claude)
Tips for Best Results
- Stage your changes thoughtfully to generate more focused commit messages
- Use conventional commit message format when possible
- Keep diffs reasonably sized for better AI analysis
- Review and edit generated messages/summaries as needed
Why This Matters
- Time Savings: Automates the often time-consuming task of writing commit messages and PR descriptions
- Consistency: Maintains a consistent style across your commit history
- Quality: Leverages AI to generate comprehensive and meaningful documentation
- Flexibility: Choose between OpenAI and Claude based on your preferences and needs
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security-related issues, please email your-email@example.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.