定制 byron/ai-git-automation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

byron/ai-git-automation

Composer 安装命令:

composer require byron/ai-git-automation

包简介

AI-powered Git automation for commit messages and PR summaries

README 文档

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:

  1. Check if there are staged changes
  2. Generate a commit message using AI based on the diff
  3. Show you the message and ask for confirmation
  4. Allow you to edit the message if needed
  5. 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

  1. Stage your changes thoughtfully to generate more focused commit messages
  2. Use conventional commit message format when possible
  3. Keep diffs reasonably sized for better AI analysis
  4. 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.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-28