A command-line tool that uses Google's Gemini AI to automatically generate pull request descriptions from git diffs. The tool analyzes the changes between your current branch and a target branch, then generates a comprehensive PR description in a standardized format.
- Python >= 3.12
- uv - Fast Python package installer and resolver
- Google API key
Clone this repository, and then follow basic usage below.
git clone https://github.com/kkeeling/pr-generator-cli.git
cd pr-generator-cli
uv run pr_generator_cli.py
The basic usage is:
uv run pr_generator_cli.py --api-key YOUR_GEMINI_API_KEY
This will:
- Compare your current branch against 'main'
- Generate a PR description using Gemini AI
- Copy the description to your clipboard
uv run pr_generator_cli.py --help
--repo-path PATH
: Path to the git repository (defaults to current directory)--template PATH/URL
: Path or URL to the XML prompt template file (defaults to GitHub URL of write-pr-volato-prompt.xml)--compare-branch TEXT
: Branch to compare against (defaults to 'main')--api-key TEXT
: Google API key (can be set via GEMINI_API_KEY or GOOGLE_API_KEY environment variable)
You can run the script directly from GitHub without cloning the repository:
uv run https://raw.githubusercontent.com/kkeeling/pr-generator-cli/refs/heads/main/pr_generator_cli.py --api-key your-api-key
This will automatically download and execute the latest version of the script.
- Using environment variable for API key:
# Using GEMINI_API_KEY
export GEMINI_API_KEY=your-api-key
uv run pr_generator_cli.py
# Or using GOOGLE_API_KEY
export GOOGLE_API_KEY=your-api-key
uv run python pr_generator_cli.py
- Comparing against a different branch:
uv run pr_generator_cli.py --compare-branch develop --api-key your-api-key
- Using a custom template (local file or URL):
# Local file
uv run pr_generator_cli.py --template custom-template.xml --api-key your-api-key
# URL
uv run pr_generator_cli.py --template https://example.com/custom-template.xml --api-key your-api-key
- Specifying a different repository:
uv run pr_generator_cli.py --repo-path /path/to/repo --api-key your-api-key
- Clone the repository:
git clone https://github.com/yourusername/pr-generator-cli.git
cd pr-generator-cli
Run the test suite:
uv run pytest
Run with coverage report:
uv run pytest --cov=pr_generator_cli
pr-generator-cli/
├── pr_generator_cli.py # Main CLI script
├── write-pr-volato-prompt.xml # Default prompt template
├── tests/ # Test directory
│ ├── conftest.py # Test configuration
│ └── test_pr_generator.py # Test cases
├── pytest.ini # Pytest configuration
└── .coveragerc # Coverage configuration
The tool uses an XML template file to structure the PR description. The default template includes:
- Pre-submission checklist
- What the PR accomplishes
- Code changes description
- Testing details
- Bug fix verification (if applicable)
- Database changes (if any)
- Additional notes
You can customize the template by creating your own XML file following the same structure as the default template.
The tool handles various error cases:
- Missing or invalid API key (checks both GEMINI_API_KEY and GOOGLE_API_KEY)
- Git repository errors
- Same branch comparison
- No differences between branches
- Missing template file
- API response errors
Error messages are descriptive and provide guidance on how to resolve the issue.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Run tests to ensure they pass
- Commit your changes (
git commit -m 'feat: Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.