pr-cli-generator
v1.5.1
Published
A simple CLI tool to generate a Git Pull Request (PR) description by analyzing your local Git commit history.
Readme
PR-CLI
A simple and powerful Command Line Interface (CLI) tool designed to streamline the process of generating Git Pull Request (PR) descriptions. By analyzing your local Git commit history and leveraging AI, PR-CLI helps you create clear, concise, and comprehensive PR descriptions, optionally using predefined templates and supporting multiple languages.
Architecture
PR-CLI operates by first analyzing your local Git commit history to extract relevant information. It then leverages an AI model (Google Gemini) to process this information, optionally integrating with predefined PR templates. The tool intelligently fills in template sections and refines the PR description based on your commit messages and chosen language, ultimately providing a structured and comprehensive output.
Features
- Automated PR Description Generation: Analyzes your Git commit history to automatically generate a structured PR description.
- Conventional Commit Support: Categorizes commit messages based on conventional commit prefixes (feat, fix, chore, docs, etc.) into organized sections.
- PR Template Integration: Automatically detects and allows you to select from
.github/PULL_REQUEST_TEMPLATEmarkdown files to structure your PR description. - AI-Enhanced Content Generation: Utilizes Google Gemini to intelligently fill in template sections and refine the PR description based on your commit messages.
- Multi-language Support: Allows you to specify the language of your PR template, enabling the AI to generate descriptions in the chosen language.
- Clipboard Integration: Automatically copies the generated PR description to your clipboard for easy pasting.
Installation
You can install pr-cli-generator via npm:
npm install -g pr-cli-generatorUsage
After installation, you can use the pr-cli command in your Git repository:
pr-cliOptions
-c,--copy: Automatically copy the generated PR description to the clipboard.pr-cli --copy-d,--description <text>: Provide a manual description to enhance the generated PR description.pr-cli --description "This PR adds a new feature for user authentication."--github(or-g): Opens a GitHub PR page in your browser with the PR title and description pre-filled in the URL. The full PR description is also copied to your clipboard, and you'll be instructed to paste it into the description field on the GitHub page.pr-cli --github--gh: Creates a GitHub PR directly using the GitHub CLI. This option also includes branch management features (prompting to create/publish a new branch if onmain/masteror if the branch is not published).pr-cli --gh--self: Assign the PR to yourself.pr-cli --gh --self--draft: Create the PR as a draft.pr-cli --gh --draft
Setup Google Gemini API Key
Obtain a GEMINI_API_KEY from Google AI Studio.
Set it as an environment variable:
# For Linux/macOS
export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
# For Windows (Command Prompt)
set GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
# For Windows (PowerShell)
$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"Alternatively, you can create a .env file in the project root with GEMINI_API_KEY=YOUR_GEMINI_API_KEY.
Workflow
- Commit your changes: Ensure your commit messages follow a consistent convention (e.g., Conventional Commits).
- Run PR-CLI: Execute
node index.jsin your repository. - Handle No Local Commits: If no local commits are found, you will be prompted to specify how many remote commits to read for history.
- Select a template (if available): If you have PR templates in
.github/PULL_REQUEST_TEMPLATE/or.github/, you will be prompted to choose one. - Select template language (if a template is chosen): You will be prompted to select the language of your chosen PR template.
- Branch Management (for
--ghoption): If using the--ghoption and onmain/masteror an unpublished branch, you will be prompted to create and/or publish a new branch. - Review and copy / Create PR:
- If using
--github, the generated PR description will be displayed, and the GitHub PR URL and full description will be copied to your clipboard. - If using
--gh, the PR will be created directly via GitHub CLI.
- If using
PR Template Example
You can create PR templates in markdown files within .github/PULL_REQUEST_TEMPLATE/ or directly in .github/.
Example: .github/PULL_REQUEST_TEMPLATE/standard.md
## Description
<!-- Briefly describe the changes introduced by this PR. -->
## Related Issues
<!-- Link any related issues (e.g., #123, #BUG-456). -->
## Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modulesContributing
Contributions are welcome! Please feel free to open issues or submit pull requests.
License
This project is licensed under the ISC License.
