PR-Creator

PR Creator with OpenAI

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.

Table of Contents

Features

Prerequisites

Usage

Inputs

Example Workflow

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: $

Setup Instructions

OpenAI API Key

  1. Sign up at OpenAI.
  2. Navigate to the API Keys section.
  3. Create a new API key.
  4. Add the API key to your repository’s secrets:
    • Go to Settings > Secrets and variables > Actions.
    • Click New repository secret.
    • Name it OPENAI_API_KEY and paste your API key.

GitHub Token

Customization

You can customize the behavior by adjusting parameters in main.py or via action inputs:

Error Handling

The script includes robust error handling:

Development

Local Testing

  1. Clone the Repository:

    git clone https://github.com/Sinless777/PR-Creator.git
    cd PR-Creator
    
  2. Install Dependencies:

    pip install -r requirements.txt
    
  3. 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
    
  4. Run the Script:

    python main.py
    

Building the Docker Image

If you need to build the Docker image locally:

docker build -t pr-creator .

Running the Docker Container

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

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -m 'Add your feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a Pull Request.

License

This project is licensed under the MIT License.

Acknowledgements