gpt-pr
gpt-pr copied to clipboard
Automate your GitHub workflow with GPT-PR: an OpenAI powered library for streamlined PR generation. #OpenSource #DevOps #Automation #AI #Github #MachineLearning
GPT-PR
GPT-PR is an open-source command-line tool designed to streamline your GitHub workflow for opening PRs. Leveraging OpenAI's ChatGPT API, it automatically opens a GitHub Pull Request with a predefined description and title directly from your current project directory.
Table of Contents
- Features
- Prerequisites
- Installation and Usage
- Authentication & API Keys
- How to Contribute
- Roadmap
Features
- Analyzes the diff changes of the current branch against the
main
branch. - Provides an option to exclude certain file changes from PR generation (for instance, you can ignore a
package.lock
file with 5k lines changed). - Incorporates commit messages into the process.
Prerequisites
Before getting started, make sure you have the following installed:
- Python 3.7 or higher
- Pipenv
Installation
You can install and use GPT-PR in one of two ways. Choose the option that best suits your needs.
Option 1: Using pip install
(Recommended)
- Install the package:
pip install -U gpt-pr
Note: Use this command to update gpt-pr package to the latest version.
-
Export API keys as environment variables (Authentication & API Keys).
-
Inside the Git repository you are working on, ensure you have pushed your branch to origin, then run:
gpt-pr --help
Option 2: Cloning the code
- Clone the repository:
git clone https://github.com/alissonperez/gpt-pr.git
- Navigate to the project directory and install dependencies:
cd gpt-pr
pipenv install
After exporting api keys as environment variables (Authentication & API Keys), you can use GPT-PR within any git project directory. Suppose you've cloned this project to ~/workplace/gpt-pr
, here's how you can use it:
PYTHONPATH=~/workplace/gpt-pr/gpt-pr \
PIPENV_PIPFILE=~/workplace/gpt-pr/Pipfile \
pipenv run python ~/workplace/gpt-pr/gptpr/main.py --help
Usage
Generating Github Pull Requests
To create a Pull request from your current branch commits to merge with main
branch, just run:
gpt-pr
If you would like to compare with other base branch that is not main
, just use -b
param:
gpt-pr -b my-other-branch
Usage help
To show help commands:
gpt-pr -h
Authentication & API Keys
Setting up GitHub Token (GH_TOKEN
)
To authenticate with GitHub, generate and export a GitHub Personal Access Token:
- Navigate to GitHub's Personal Access Token page.
- Click "Generate new token."
- Provide a description and select the required permissions
repo
for the token. - Click "Generate token" at the bottom of the page.
- Copy the generated token.
- Export it as an environment variable:
export GH_TOKEN=your_generated_token_here
Setting up OpenAI API Key (OPENAI_API_KEY
)
This project needs to interact with the ChatGPT API to generate the pull request description. So, you need to generate and export an OpenAI API Key:
- Navigate to OpenAI's API Key page.
- If you don't have an account, sign up and log in.
- Go to the API Keys section and click "Create new key."
- Provide a description and click "Create."
- Copy the generated API key.
- Export it as an environment variable:
export OPENAI_API_KEY=your_generated_api_key_here
Output:
How to contribute?
Please follow our CONTRIBUTING guide.
Roadmap
- [x] Improve execution method, possibly through a shell script or at least an alias in bash rc files.
- Change to use with pip installation and console_scripts entry point.
- [x] Fetch GitHub PR templates from the current project.
- [ ] Add configuration to set which LLM and model should be used (OpenAI GPT, Mistral, etc...)
- [ ] Add unit tests.