Skip to content

Commit 2cd57d9

Browse files
authored
Merge pull request #2 from ravilushqa/github_action
github action
2 parents 399a81f + dc54833 commit 2cd57d9

File tree

3 files changed

+145
-39
lines changed

3 files changed

+145
-39
lines changed

.github/workflows/cr.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: GPT Pull Request Updater
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
jobs:
10+
update_pull_request:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Set up Go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: 1.19
18+
19+
- name: Checkout GPT-PullRequest-Updater
20+
uses: actions/checkout@v2
21+
with:
22+
repository: ravilushqa/gpt-pullrequest-updater
23+
path: gpt-pullrequest-updater
24+
25+
- name: Build description and review commands
26+
run: |
27+
cd gpt-pullrequest-updater
28+
go build -o description ./cmd/description
29+
go build -o review ./cmd/review
30+
31+
- name: Update Pull Request Description
32+
run: |
33+
./gpt-pullrequest-updater/description
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
37+
OWNER: ${{ github.repository_owner }}
38+
REPO: ${{ github.event.repository.name }}
39+
PR_NUMBER: ${{ github.event.number }}
40+
41+
- name: Review Pull Request
42+
if: github.event.action == 'opened'
43+
run: |
44+
./gpt-pullrequest-updater/review
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
48+
OWNER: ${{ github.repository_owner }}
49+
REPO: ${{ github.event.repository.name }}
50+
PR_NUMBER: ${{ github.event.number }}

README.md

Lines changed: 95 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,115 @@ This repository contains a tool for updating and reviewing GitHub pull requests
3030

3131
## Usage
3232

33-
Before running the commands, make sure you have set the following environment variables:
33+
### Review Command
3434

35-
- `GITHUB_TOKEN`: Your GitHub token
36-
- `OPENAI_TOKEN`: Your OpenAI API token
37-
- `OWNER`: The owner of the GitHub repository
38-
- `REPO`: The name of the GitHub repository
39-
- `PR_NUMBER`: The pull request number you want to update or review
35+
Usage:
36+
```
37+
review [OPTIONS]
38+
```
4039

41-
### Description Command
40+
Application Options:
41+
```
42+
--gh-token= GitHub token [$GITHUB_TOKEN]
43+
--openai-token= OpenAI token [$OPENAI_TOKEN]
44+
--owner= GitHub owner [$OWNER]
45+
--repo= GitHub repo [$REPO]
46+
--pr-number= Pull request number [$PR_NUMBER]
47+
--test Test mode [$TEST]
48+
```
49+
50+
Help Options:
51+
```
52+
-h, --help Show this help message
53+
```
4254

43-
The `description` command updates the pull request description with a high-level summary of the changes made. To run the command, execute:
55+
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.
56+
57+
To run the `review` command, execute:
4458

4559
```
46-
./description
60+
./review --gh-token=<GITHUB_TOKEN> --openai-token=<OPENAI_TOKEN> --owner=<OWNER> --repo=<REPO> --pr-number=<PR_NUMBER> --test
4761
```
4862

49-
### Review Command
63+
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.
5064

51-
The `review` command creates individual comments for each file and an overall review summary comment. To run the command, execute:
65+
### Description Command
66+
67+
The usage for the `description` command is similar to the `review` command. Replace `review` with `description` in the command above and execute.
68+
69+
70+
## GitHub Action
71+
72+
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`.
73+
74+
Here's an example of what the workflow file could look like:
75+
76+
```yaml
77+
name: GPT Pull Request Updater
78+
79+
on:
80+
pull_request:
81+
types:
82+
- opened
83+
- synchronize
84+
85+
jobs:
86+
update_pull_request:
87+
runs-on: ubuntu-latest
88+
89+
steps:
90+
- name: Set up Go
91+
uses: actions/setup-go@v2
92+
with:
93+
go-version: 1.19
94+
95+
- name: Checkout GPT-PullRequest-Updater
96+
uses: actions/checkout@v2
97+
with:
98+
repository: ravilushqa/gpt-pullrequest-updater
99+
path: gpt-pullrequest-updater
100+
101+
- name: Build description and review commands
102+
run: |
103+
cd gpt-pullrequest-updater
104+
go build -o description ./cmd/description
105+
go build -o review ./cmd/review
106+
107+
- name: Update Pull Request Description
108+
run: |
109+
./gpt-pullrequest-updater/description
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
113+
OWNER: ${{ github.repository_owner }}
114+
REPO: ${{ github.event.repository.name }}
115+
PR_NUMBER: ${{ github.event.number }}
116+
117+
- name: Review Pull Request
118+
if: github.event.action == 'opened'
119+
run: |
120+
./gpt-pullrequest-updater/review
121+
env:
122+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
124+
OWNER: ${{ github.repository_owner }}
125+
REPO: ${{ github.event.repository.name }}
126+
PR_NUMBER: ${{ github.event.number }}
52127

53-
```
54-
./review
55128
```
56129

57-
### Test Mode
130+
Make sure to add your OpenAI API token to your repository secrets as `OPENAI_TOKEN`.
58131

59-
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`:
132+
### Granting Permissions for GitHub Actions
60133

61-
```
62-
export TEST=true
63-
```
134+
In order to use this GitHub Action, you need to grant the necessary permissions to the GitHub token. To do this, follow these steps:
64135

65-
Then, run the desired command as described above. The generated content will be printed to the console.
136+
1. Go to the repository settings page: https://github.com/OWNER/REPO/settings
137+
2. Navigate to the "Actions" tab on the left side of the settings page.
138+
3. Scroll down to the "Workflow Permissions" section.
66139

67-
## License
140+
Select "Read and Write" permissions for the actions. This will provide your token with the necessary rights to modify your repository.
141+
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.
68142

143+
License
69144
This project is licensed under the MIT License.

0 commit comments

Comments
 (0)