A PHP library that generates meaningful and standardized Git commit messages using AI powered by Groq API. This tool analyzes your git diff and generates commit messages that follow best practices and conventional commit standards.
- AI-powered commit message generation
- Follows conventional commit message standards
- Analyzes git diff to understand code changes
- Generates both commit titles and detailed descriptions
- Easy integration with existing PHP projects
- PHP 8.0 or higher
- Composer
- Groq API key
You can install the package via composer:
composer require ay4t/php-commit-generator
You can use the library directly from your workspace using CLI command. But you need to provide GROQ API key first. Example:
EXPORT GROQ_API_KEY=your-groq-api-key
php /path/to/generate.php -d /path/to/directory
or if you working with current directory you can simply
php /path/to/generate.php -d ./
use Ay4t\PCGG\Commit;
// Initialize with your Groq API key
$commit = new Commit('your-groq-api-key');
// Provide git diff
$diff = shell_exec('git diff --staged');
$commit->gitDiff($diff);
// Generate commit message
$message = $commit->generate();
echo $message;
The package includes a CLI script for easy usage:
- Set your Groq API key:
export GROQ_API_KEY=your-groq-api-key
- Run the generator:
php generate.php
The script will automatically:
- Get staged changes using
git diff --staged
- Generate an appropriate commit message
- Output the message ready for use
The generated commit messages follow this format:
<type>(<scope>): <short summary>
<detailed description>
- Change 1 details
- Change 2 details
Where:
type
: The type of change (feat, fix, docs, style, refactor, test, chore)scope
: The scope of changes (optional)summary
: A brief description of changesdetailed description
: A more comprehensive explanation of the changes
The commit message generator is configured to follow best practices:
- Commit titles are limited to 50 characters
- Descriptions are wrapped at 72 characters
- Follows conventional commit format
- Includes relevant context and reasoning
The library includes comprehensive error handling:
try {
$commit = new Commit($apiKey);
$commit->gitDiff($diff);
$message = $commit->generate();
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}
Run the test suite:
composer test
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Author: Ayatulloh Ahad R
- Powered by Groq API
If you encounter any problems or have suggestions, please open an issue.