Skip to content

Commit eb6ebaf

Browse files
committed
wip
1 parent e761919 commit eb6ebaf

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

github.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,32 @@ func NewGithubClient(ctx context.Context, token string) *GithubClient {
2222
return &GithubClient{github.NewClient(tc)}
2323
}
2424

25-
func (g *GithubClient) GetPullRequestFiles(ctx context.Context, owner, repo string, prNumber int) ([]*github.CommitFile, error) {
26-
files, _, err := g.client.PullRequests.ListFiles(ctx, owner, repo, prNumber, nil)
25+
func (c *GithubClient) GetPullRequestFiles(ctx context.Context, owner, repo string, prNumber int) ([]*github.CommitFile, error) {
26+
files, _, err := c.client.PullRequests.ListFiles(ctx, owner, repo, prNumber, nil)
2727
return files, err
2828
}
2929

30-
func (g *GithubClient) GetPullRequest(ctx context.Context, owner, repo string, number int) (*github.PullRequest, error) {
31-
pr, _, err := g.client.PullRequests.Get(ctx, owner, repo, number)
30+
func (c *GithubClient) GetPullRequest(ctx context.Context, owner, repo string, number int) (*github.PullRequest, error) {
31+
pr, _, err := c.client.PullRequests.Get(ctx, owner, repo, number)
3232
return pr, err
3333
}
3434

35-
func (g *GithubClient) GetPullRequestDiff(ctx context.Context, owner, repo string, number int) (string, error) {
36-
diff, _, err := g.client.PullRequests.GetRaw(ctx, owner, repo, number, github.RawOptions{Type: github.Diff})
35+
func (c *GithubClient) GetPullRequestDiff(ctx context.Context, owner, repo string, number int) (string, error) {
36+
diff, _, err := c.client.PullRequests.GetRaw(ctx, owner, repo, number, github.RawOptions{Type: github.Diff})
3737
return diff, err
3838
}
3939

40-
func (g *GithubClient) UpdatePullRequest(ctx context.Context, owner, repo string, number int, pr *github.PullRequest) (*github.PullRequest, error) {
41-
updatedPR, _, err := g.client.PullRequests.Edit(ctx, owner, repo, number, pr)
40+
func (c *GithubClient) UpdatePullRequest(ctx context.Context, owner, repo string, number int, pr *github.PullRequest) (*github.PullRequest, error) {
41+
updatedPR, _, err := c.client.PullRequests.Edit(ctx, owner, repo, number, pr)
4242
return updatedPR, err
4343
}
44+
45+
func (c *GithubClient) CreateComment(ctx context.Context, owner, repo string, number int, comment *github.PullRequestComment) (*github.PullRequestComment, error) {
46+
createdComment, _, err := c.client.PullRequests.CreateComment(ctx, owner, repo, number, comment)
47+
return createdComment, err
48+
}
49+
50+
func (c *GithubClient) CompareCommits(ctx context.Context, owner, repo, base, head string) (*github.CommitsComparison, error) {
51+
comp, _, err := c.client.Repositories.CompareCommits(ctx, owner, repo, base, head, nil)
52+
return comp, err
53+
}

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ func main() {
5757
fileName := getFilenameFromDiffHeader(fileDiff.Header)
5858

5959
prompt := fmt.Sprintf("File %s:\n%s\n%s\n", fileName, fileDiff.Header, fileDiff.Diff)
60-
messages = append(messages, openai.ChatCompletionMessage{
60+
messages = append(messages, openai.CompletionRequest{
6161
Role: openai.ChatMessageRoleUser,
6262
Content: prompt,
6363
})
64+
65+
fmt.Println(fileName, len(prompt))
6466
}
67+
os.Exit(0)
6568
chatGPTDescription, err := openaiClient.ChatCompletion(context.Background(), messages)
6669
if err != nil {
6770
fmt.Printf("Error generating pull request description: %v\n", err)
@@ -74,6 +77,14 @@ func main() {
7477
return
7578
}
7679

80+
//compare base branch with head branch
81+
commitsComparison, err := githubClient.CompareCommits(context.Background(), opts.Owner, opts.Repo, pr.GetBase().GetRef(), pr.GetHead().GetRef())
82+
if err != nil {
83+
return
84+
}
85+
86+
_ = commitsComparison
87+
7788
jiraLink := generateJiraLinkByTitle(*pr.Title)
7889

7990
description := fmt.Sprintf("### Jira\n%s\n%s", jiraLink, chatGPTDescription)

openai.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
)
99

1010
const (
11-
PromptUpdateDesription = "\"Generate a GitHub pull request description based on the following changes without basic prefix in markdown format with ###Description and ###Changes blocks:\\n\""
11+
PromptUpdateDescription = "\"Generate a GitHub pull request description based on the following changes without basic prefix in markdown format with ###Description and ###Changes blocks:\\n\""
12+
PromptDescribeChanges = "Bellow is the code patch, please describe the changes in the following format: **file name**:\\n###Description\\n###Changes\\n"
1213
)
1314

1415
type OpenAIClient struct {
@@ -22,8 +23,9 @@ func NewOpenAIClient(token string) *OpenAIClient {
2223
}
2324

2425
func (o *OpenAIClient) ChatCompletion(ctx context.Context, messages []openai.ChatCompletionMessage) (string, error) {
26+
return "", nil
2527
resp, err := o.client.CreateChatCompletion(
26-
context.Background(),
28+
ctx,
2729
openai.ChatCompletionRequest{
2830
Model: openai.GPT3Dot5Turbo,
2931
Messages: messages,

0 commit comments

Comments
 (0)