Skip to content

github action #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .github/workflows/cr.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/gpt_pullrequest_updater.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the code patch looks good. Here are some suggestions:

  • In the "Set up Go" step, it might be helpful to specify a more specific Go version instead of using "1.19", which could become outdated.
  • Instead of hardcoding the repository owner and name in the "Checkout GPT-PullRequest-Updater" step, consider using the predefined "github" context variables. For example, you can use "github.repository_owner" and "github.event.repository.name" to get the owner and name of the repository where the pull request was opened/synchronized.
  • In the "Update Pull Request Description" and "Review Pull Request" steps, it might be a good idea to add some error handling and logging to make troubleshooting easier if something goes wrong.
  • Consider adding some comments to explain what each step does and why it's needed. This can be helpful for other contributors who might not be familiar with the codebase.

115 changes: 95 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<GITHUB_TOKEN> --openai-token=<OPENAI_TOKEN> --owner=<OWNER> --repo=<REPO> --pr-number=<PR_NUMBER> --test
```

### Review Command
Replace `<GITHUB_TOKEN>`, `<OPENAI_TOKEN>`, `<OWNER>`, `<REPO>`, and `<PR_NUMBER>` 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.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code patch adds a tool for updating and reviewing GitHub pull requests. The commands review and description are used to review pull requests and update the pull request description, respectively. The code also includes a GitHub action that can automatically run the review and description commands when a pull request is opened or synchronized.

The review and description commands require environment variables to be set, and the GitHub action uses secrets to access the necessary tokens. Test mode can be enabled by adding the --test flag.

Improvement suggestions:

  • Provide more detailed documentation on how to set the necessary environment variables and secrets.
  • Add error handling and logging to provide more informative error messages when there are issues.
  • Consider using a more descriptive name for the GitHub action workflow, to make it clear what it does.