Automatically create a Pull Request (PR) with OpenAI-generated content when code is pushed to a branch without an existing PR. This GitHub Action uses Python and Bash to automate the PR creation process, including generating PR titles, descriptions, and comments using OpenAI’s GPT-3 language model.
commitlint
.$
is sufficient).openai_api_key
(required): Your OpenAI API key for generating PR information.github_token
(required): GitHub token for accessing the repository and making API calls.repository_owner
(required): GitHub repository owner (username or organization).repository
(required): GitHub repository name.branch
(required): Branch name to create the PR for.head
(required): Commit SHA for the head of the branch.Create a workflow file (e.g., .github/workflows/pr-creator.yml
) in your repository:
name: PR Creator
on:
push:
branches:
- '**'
jobs:
create_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: PR Creator with OpenAI
uses: Sinless777/PR-Creator@v1
with:
openai_api_key: $
github_token: $
repository_owner: $
repository: $
branch: $
head: $
OPENAI_API_KEY
and paste your API key.$
is automatically provided by GitHub Actions.You can customize the behavior by adjusting parameters in main.py
or via action inputs:
temperature
: Controls randomness (range 0 to 1). Lower values make output more deterministic.max_tokens
: Maximum number of tokens to generate.limit
parameter in the get_commit_history(limit=10)
function.The script includes robust error handling:
Clone the Repository:
git clone https://github.com/Sinless777/PR-Creator.git
cd PR-Creator
Install Dependencies:
pip install -r requirements.txt
Set Environment Variables:
export OPENAI_API_KEY=your_openai_api_key
export GITHUB_TOKEN=your_github_token
export REPO_OWNER=your_repo_owner
export REPO_NAME=your_repo_name
export REPO_BRANCH=your_branch_name
export REPO_HEAD=your_commit_sha
Run the Script:
python main.py
If you need to build the Docker image locally:
docker build -t pr-creator .
docker run --rm \
-e OPENAI_API_KEY=your_openai_api_key \
-e GITHUB_TOKEN=your_github_token \
-e REPO_OWNER=your_repo_owner \
-e REPO_NAME=your_repo_name \
-e REPO_BRANCH=your_branch_name \
-e REPO_HEAD=your_commit_sha \
pr-creator
Contributions are welcome! Please follow these steps:
git checkout -b feature/your-feature
).git commit -m 'Add your feature'
).git push origin feature/your-feature
).This project is licensed under the MIT License.