jesse-bos / openai-commit-messages
A Laravel package that generates AI-powered commit messages using OpenAI
Fund package maintenance!
Jesse Bos
Requires
- php: ^8.3
- illuminate/contracts: ^11.0||^12.0
- openai-php/laravel: ^0.13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
OpenAI Commit Messages is a Laravel package that generates meaningful commit messages using OpenAI based on your git changes. It first checks for staged changes, and if none are found, analyzes unstaged changes. Just run one command and get a suggested commit message!
Installation
Step 1: Install the Package
composer require jesse-bos/openai-commit-messages --dev
This automatically installs the required OpenAI Laravel package as well.
Step 2: Publish OpenAI Configuration
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
Step 3: Add your OpenAI API Key
- Get an API key from OpenAI's website
- Add it to your
.env
file:
OPENAI_API_KEY=sk-your-actual-api-key-here
Step 4: Optionally configure the Package
If you want to customize the OpenAI model, publish the package config:
php artisan vendor:publish --tag="openai-commit-messages-config"
Prerequisites
- PHP 8.3+
- Laravel 11.0+ or 12.0+
- OpenAI API key with sufficient credits
Usage
Verify your setup (recommended first time)
After installation, verify that everything is configured correctly by running the command. The package will automatically check:
- ✓ OpenAI API key is set
- ✓ OpenAI configuration is published
- ✓ You're in a git repository
- ✓ Model configuration
Generate commit messages
After making changes in your git repository, simply run:
php artisan openai:commit-message
The package will automatically:
- First check for staged changes (files added with
git add
or staged via Tower, GitHub Desktop, etc.) - If no staged changes found, it will analyze unstaged changes
- Generate a commit message based on the found changes using OpenAI
The tool works seamlessly with any git workflow:
- Command line:
git add .
thenphp artisan openai:commit-message
- Tower/GitHub Desktop: Stage files in the GUI, then run
php artisan openai:commit-message
- Quick preview: Just run
php artisan openai:commit-message
to see a message for unstaged changes
After getting the suggested message, create your commit:
git commit -m "the suggested message"
Configuration
You can configure the package by publishing and editing the config file:
php artisan vendor:publish --tag="openai-commit-messages-config"
Available Configuration Options
return [ 'openai' => [ // OpenAI model to use for generating commit messages 'model' => env('OPENAI_COMMIT_MESSAGES_MODEL', 'gpt-4o-mini'), ], 'commit' => [ // Maximum length for the commit message 'max_length' => 72, // Use conventional commit format (e.g. feat: message, fix: bug) 'conventional' => true, ], ];
Environment Variables
You can also configure the OpenAI model using an environment variable:
OPENAI_COMMIT_MESSAGES_MODEL=gpt-4o
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.