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"

review/utils_test.go renamed to cmd/review/utils_test.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
"reflect"

go.mod

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@ require (
66
github.com/google/go-github/v51 v51.0.0
77
github.com/jessevdk/go-flags v1.5.0
88
github.com/sashabaranov/go-openai v1.7.0
9-
github.com/stretchr/testify v1.8.2
109
golang.org/x/oauth2 v0.6.0
1110
)
1211

1312
require (
1413
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
1514
github.com/cloudflare/circl v1.1.0 // indirect
16-
github.com/davecgh/go-spew v1.1.1 // indirect
1715
github.com/golang/protobuf v1.5.2 // indirect
1816
github.com/google/go-querystring v1.1.0 // indirect
19-
github.com/pmezard/go-difflib v1.0.0 // indirect
20-
github.com/stretchr/objx v0.5.0 // indirect
2117
golang.org/x/crypto v0.7.0 // indirect
2218
golang.org/x/net v0.8.0 // indirect
2319
golang.org/x/sys v0.6.0 // indirect
2420
google.golang.org/appengine v1.6.7 // indirect
2521
google.golang.org/protobuf v1.28.0 // indirect
26-
gopkg.in/yaml.v3 v3.0.1 // indirect
2722
)

go.sum

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0g
33
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
44
github.com/cloudflare/circl v1.1.0 h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GKY=
55
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
6-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
96
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
107
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
118
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
@@ -19,18 +16,8 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
1916
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
2017
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
2118
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
22-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
23-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2419
github.com/sashabaranov/go-openai v1.7.0 h1:D1dBXoZhtf/aKNu6WFf0c7Ah2NM30PZ/3Mqly6cZ7fk=
2520
github.com/sashabaranov/go-openai v1.7.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
26-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
27-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
28-
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
29-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
30-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
31-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
32-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
33-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
3421
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3522
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
3623
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
@@ -60,8 +47,3 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
6047
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
6148
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
6249
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
63-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
64-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
65-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
66-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
67-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

jira/jira.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"regexp"
66
)
77

8-
const ticketURLFormat = "%s/browse/%s"
8+
const ticketUrlFormat = "%s/browse/%s"
99

1010
// ExtractJiraTicketID returns the first JIRA ticket ID found in the input string.
1111
func ExtractJiraTicketID(s string) (string, error) {
@@ -25,5 +25,5 @@ func ExtractJiraTicketID(s string) (string, error) {
2525
}
2626

2727
func GenerateJiraTicketURL(jiraURL, ticketID string) string {
28-
return fmt.Sprintf(ticketURLFormat, jiraURL, ticketID)
28+
return fmt.Sprintf(ticketUrlFormat, jiraURL, ticketID)
2929
}

openai/openai.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/sashabaranov/go-openai"
99
)
1010

11-
//go:embed prompts/review
11+
//go:embed prompt-review.txt
1212
var PromptReview string
1313

1414
const (
File renamed without changes.

0 commit comments

Comments
 (0)