Skip to content

Commit c6d76ad

Browse files
authored
Merge pull request #21 from ravilushqa/revert-18-refactor
Revert "Refactor"
2 parents a44b90b + e6c5b0d commit c6d76ad

File tree

20 files changed

+30
-1514
lines changed

20 files changed

+30
-1514
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/gpt_pullrequest_updater.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ jobs:
2525
- name: Build description and review commands
2626
run: |
2727
cd gpt-pullrequest-updater
28-
make build
28+
go build -o description ./cmd/description
29+
go build -o review ./cmd/review
2930
3031
- name: Update Pull Request Description
3132
run: |
32-
./gpt-pullrequest-updater/bin/description
33+
./gpt-pullrequest-updater/description
3334
env:
3435
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3536
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
@@ -40,7 +41,7 @@ jobs:
4041
- name: Review Pull Request
4142
if: github.event.action == 'opened'
4243
run: |
43-
./gpt-pullrequest-updater/bin/review
44+
./gpt-pullrequest-updater/review
4445
env:
4546
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4647
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}

.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.golangci.yaml

Lines changed: 0 additions & 41 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 45 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ jobs:
101101
- name: Build description and review commands
102102
run: |
103103
cd gpt-pullrequest-updater
104-
make build
104+
go build -o description ./cmd/description
105+
go build -o review ./cmd/review
105106
106107
- name: Update Pull Request Description
107108
run: |
108-
./gpt-pullrequest-updater/bin/description
109+
./gpt-pullrequest-updater/description
109110
env:
110111
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111112
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
@@ -116,7 +117,7 @@ jobs:
116117
- name: Review Pull Request
117118
if: github.event.action == 'opened'
118119
run: |
119-
./gpt-pullrequest-updater/bin/review
120+
./gpt-pullrequest-updater/review
120121
env:
121122
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122123
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}

cmd/review/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
var opts struct {
4+
GithubToken string `long:"gh-token" env:"GITHUB_TOKEN" description:"GitHub token" required:"true"`
5+
OpenAIToken string `long:"openai-token" env:"OPENAI_TOKEN" description:"OpenAI token" required:"true"`
6+
Owner string `long:"owner" env:"OWNER" description:"GitHub owner" required:"true"`
7+
Repo string `long:"repo" env:"REPO" description:"GitHub repo" required:"true"`
8+
PRNumber int `long:"pr-number" env:"PR_NUMBER" description:"Pull request number" required:"true"`
9+
Test bool `long:"test" env:"TEST" description:"Test mode"`
10+
}

cmd/review/main.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,8 @@ import (
1111

1212
ghClient "github.com/ravilushqa/gpt-pullrequest-updater/github"
1313
oAIClient "github.com/ravilushqa/gpt-pullrequest-updater/openai"
14-
"github.com/ravilushqa/gpt-pullrequest-updater/review"
1514
)
1615

17-
var opts struct {
18-
GithubToken string `long:"gh-token" env:"GITHUB_TOKEN" description:"GitHub token" required:"true"`
19-
OpenAIToken string `long:"openai-token" env:"OPENAI_TOKEN" description:"OpenAI token" required:"true"`
20-
Owner string `long:"owner" env:"OWNER" description:"GitHub owner" required:"true"`
21-
Repo string `long:"repo" env:"REPO" description:"GitHub repo" required:"true"`
22-
PRNumber int `long:"pr-number" env:"PR_NUMBER" description:"Pull request number" required:"true"`
23-
Test bool `long:"test" env:"TEST" description:"Test mode"`
24-
}
25-
2616
func main() {
2717
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
2818
defer cancel()
@@ -53,17 +43,16 @@ func run(ctx context.Context) error {
5343
return fmt.Errorf("error getting commits: %w", err)
5444
}
5545

56-
comments, err := review.GenerateCommentsFromDiff(ctx, openAIClient, diff)
46+
comments, err := processFiles(ctx, openAIClient, diff)
5747
if err != nil {
5848
return err
5949
}
6050

6151
if opts.Test {
6252
fmt.Printf("Comments: %v \n", comments)
63-
return nil
6453
}
6554

66-
err = review.PushComments(ctx, githubClient, opts.Owner, opts.Repo, opts.PRNumber, comments)
55+
err = createComments(ctx, githubClient, comments)
6756
if err != nil {
6857
return fmt.Errorf("error creating comments: %w", err)
6958
}

review/review.go renamed to cmd/review/review.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package review
1+
package main
22

33
import (
44
"context"
@@ -7,17 +7,10 @@ import (
77
"github.com/google/go-github/v51/github"
88
"github.com/sashabaranov/go-openai"
99

10+
ghClient "github.com/ravilushqa/gpt-pullrequest-updater/github"
1011
oAIClient "github.com/ravilushqa/gpt-pullrequest-updater/openai"
1112
)
1213

13-
type PullRequestUpdater interface {
14-
CreatePullRequestComment(ctx context.Context, owner, repo string, number int, comment *github.PullRequestComment) (*github.PullRequestComment, error)
15-
}
16-
17-
type Completer interface {
18-
ChatCompletion(ctx context.Context, messages []openai.ChatCompletionMessage) (string, error)
19-
}
20-
2114
type Review struct {
2215
Quality Quality `json:"quality"`
2316
Issues []Issue `json:"issues"`
@@ -37,7 +30,7 @@ const (
3730
Neutral Quality = "neutral"
3831
)
3932

40-
func GenerateCommentsFromDiff(ctx context.Context, openAIClient Completer, diff *github.CommitsComparison) ([]*github.PullRequestComment, error) {
33+
func processFiles(ctx context.Context, openAIClient *oAIClient.Client, diff *github.CommitsComparison) ([]*github.PullRequestComment, error) {
4134
var comments []*github.PullRequestComment
4235

4336
for i, file := range diff.Files {
@@ -97,10 +90,10 @@ func GenerateCommentsFromDiff(ctx context.Context, openAIClient Completer, diff
9790
return comments, nil
9891
}
9992

100-
func PushComments(ctx context.Context, prUpdated PullRequestUpdater, owner, repo string, number int, comments []*github.PullRequestComment) error {
93+
func createComments(ctx context.Context, githubClient *ghClient.Client, comments []*github.PullRequestComment) error {
10194
for i, c := range comments {
10295
fmt.Printf("creating comment: %s %d/%d\n", *c.Path, i+1, len(comments))
103-
if _, err := prUpdated.CreatePullRequestComment(ctx, owner, repo, number, c); err != nil {
96+
if _, err := githubClient.CreatePullRequestComment(ctx, opts.Owner, opts.Repo, opts.PRNumber, c); err != nil {
10497
return fmt.Errorf("error creating comment: %w", err)
10598
}
10699
}

review/utils.go renamed to cmd/review/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package review
1+
package main
22

33
import (
44
"encoding/json"

0 commit comments

Comments
 (0)