diff --git a/.github/workflows/cr.yml b/.github/workflows/cr.yml deleted file mode 100644 index 240ba7c..0000000 --- a/.github/workflows/cr.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Code Review - -permissions: - contents: read - pull-requests: write - -on: - pull_request: - types: [opened, reopened, synchronize] - -jobs: - test: -# if: ${{ contains(github.event.*.labels.*.name, 'gpt review') }} # Optional; to run only when a label is attached - runs-on: ubuntu-latest - steps: - - uses: anc95/ChatGPT-CodeReview@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} \ No newline at end of file diff --git a/.github/workflows/gpt_pullrequest_updater.yml b/.github/workflows/gpt_pullrequest_updater.yml new file mode 100644 index 0000000..2acc0c2 --- /dev/null +++ b/.github/workflows/gpt_pullrequest_updater.yml @@ -0,0 +1,50 @@ +name: GPT Pull Request Updater + +on: + pull_request: + types: + - opened + - synchronize + +jobs: + update_pull_request: + runs-on: ubuntu-latest + + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + + - name: Checkout GPT-PullRequest-Updater + uses: actions/checkout@v2 + with: + repository: ravilushqa/gpt-pullrequest-updater + path: gpt-pullrequest-updater + + - name: Build description and review commands + run: | + cd gpt-pullrequest-updater + go build -o description ./cmd/description + go build -o review ./cmd/review + + - name: Update Pull Request Description + run: | + ./gpt-pullrequest-updater/description + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.number }} + + - name: Review Pull Request + if: github.event.action == 'opened' + run: | + ./gpt-pullrequest-updater/review + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.number }} diff --git a/README.md b/README.md index 87a772b..d428685 100644 --- a/README.md +++ b/README.md @@ -30,40 +30,115 @@ This repository contains a tool for updating and reviewing GitHub pull requests ## Usage -Before running the commands, make sure you have set the following environment variables: +### Review Command -- `GITHUB_TOKEN`: Your GitHub token -- `OPENAI_TOKEN`: Your OpenAI API token -- `OWNER`: The owner of the GitHub repository -- `REPO`: The name of the GitHub repository -- `PR_NUMBER`: The pull request number you want to update or review +Usage: + ``` + review [OPTIONS] + ``` -### Description Command +Application Options: + ``` + --gh-token= GitHub token [$GITHUB_TOKEN] + --openai-token= OpenAI token [$OPENAI_TOKEN] + --owner= GitHub owner [$OWNER] + --repo= GitHub repo [$REPO] + --pr-number= Pull request number [$PR_NUMBER] + --test Test mode [$TEST] + ``` + +Help Options: + ``` + -h, --help Show this help message + ``` -The `description` command updates the pull request description with a high-level summary of the changes made. To run the command, execute: +Before running the command, make sure you have set the appropriate options or environment variables. The command line options will take precedence over the environment variables. + +To run the `review` command, execute: ``` -./description +./review --gh-token= --openai-token= --owner= --repo= --pr-number= --test ``` -### Review Command +Replace ``, ``, ``, ``, and `` with the appropriate values. If you want to enable test mode, add the `--test` flag. -The `review` command creates individual comments for each file and an overall review summary comment. To run the command, execute: +### Description Command + +The usage for the `description` command is similar to the `review` command. Replace `review` with `description` in the command above and execute. + + +## GitHub Action + +This script can be used as a GitHub Action, allowing it to run automatically in your repository. To get started, add a new workflow file in your repository, such as: `.github/workflows/gpt_pullrequest_updater.yml`. + +Here's an example of what the workflow file could look like: + +```yaml +name: GPT Pull Request Updater + +on: + pull_request: + types: + - opened + - synchronize + +jobs: + update_pull_request: + runs-on: ubuntu-latest + + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + + - name: Checkout GPT-PullRequest-Updater + uses: actions/checkout@v2 + with: + repository: ravilushqa/gpt-pullrequest-updater + path: gpt-pullrequest-updater + + - name: Build description and review commands + run: | + cd gpt-pullrequest-updater + go build -o description ./cmd/description + go build -o review ./cmd/review + + - name: Update Pull Request Description + run: | + ./gpt-pullrequest-updater/description + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.number }} + + - name: Review Pull Request + if: github.event.action == 'opened' + run: | + ./gpt-pullrequest-updater/review + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.number }} -``` -./review ``` -### Test Mode +Make sure to add your OpenAI API token to your repository secrets as `OPENAI_TOKEN`. -Both commands support a test mode that prints the generated content to the console instead of updating the pull request. To enable test mode, set the `TEST` environment variable to `true`: +### Granting Permissions for GitHub Actions -``` -export TEST=true -``` +In order to use this GitHub Action, you need to grant the necessary permissions to the GitHub token. To do this, follow these steps: -Then, run the desired command as described above. The generated content will be printed to the console. +1. Go to the repository settings page: https://github.com/OWNER/REPO/settings +2. Navigate to the "Actions" tab on the left side of the settings page. +3. Scroll down to the "Workflow Permissions" section. -## License +Select "Read and Write" permissions for the actions. This will provide your token with the necessary rights to modify your repository. +By following these steps, you'll grant the required permissions for the GPT-PullRequest-Updater GitHub Action to function properly, allowing it to update and review pull requests in your repository. +License This project is licensed under the MIT License. \ No newline at end of file