some changes

make some unnecessary logging debug logs
add some randomness into branch name
create directories as necessary if they don't exist
This commit is contained in:
Moby von Briesen 2023-05-15 19:23:36 -04:00
parent 157212c5fb
commit dfef07a1c0
3 changed files with 17 additions and 9 deletions

View File

@ -6,7 +6,9 @@ File:
``` ```
Diff: Diff:
```
{{ .Diff }} {{ .Diff }}
```
Comment: Comment:
{{ .Contents }} {{ .Contents }}
@ -14,8 +16,8 @@ Comment:
The above is information about a comment left on a file. The diff contains information about the precise location of the comment. The above is information about a comment left on a file. The diff contains information about the precise location of the comment.
First, determine if the comment is a question or a request for changes. First, determine if the comment is a question or a request for changes.
If the comment is a question, come up with an answer, and respond exactly as outlined directly below "Response Template A" If the comment is a question, come up with an answer, and respond exactly as outlined directly below "Response Template A", starting with "Q".
If the comment is a request, modify the file provided at the beginning of the message, and respond exactly as outlined directly below "Response Template B". If the comment is a request, modify the file provided at the beginning of the message, and respond exactly as outlined directly below "Response Template B", starting with "R".
Response Template A: Response Template A:
Q Q

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"math/rand"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
@ -56,7 +57,6 @@ func NewPullPal(ctx context.Context, log *zap.Logger, cfg Config) (*PullPal, err
openAIClient := llm.NewOpenAIClient(log.Named("openaiClient"), cfg.Model, cfg.OpenAIToken) openAIClient := llm.NewOpenAIClient(log.Named("openaiClient"), cfg.Model, cfg.OpenAIToken)
ppRepos := []pullPalRepo{} ppRepos := []pullPalRepo{}
fmt.Println("asdfasfdasfasdfasdf")
for _, r := range cfg.Repos { for _, r := range cfg.Repos {
fmt.Println(r) fmt.Println(r)
parts := strings.Split(r, "/") parts := strings.Split(r, "/")
@ -130,7 +130,7 @@ func (p *PullPal) Run() error {
// checkIssuesAndComments will attempt to find and solve one issue and one comment, and then return. // checkIssuesAndComments will attempt to find and solve one issue and one comment, and then return.
func (p pullPalRepo) checkIssuesAndComments() error { func (p pullPalRepo) checkIssuesAndComments() error {
p.log.Info("checking github issues...") p.log.Debug("checking github issues...")
issues, err := p.ghClient.ListOpenIssues(p.listIssueOptions) issues, err := p.ghClient.ListOpenIssues(p.listIssueOptions)
if err != nil { if err != nil {
p.log.Error("error listing issues", zap.Error(err)) p.log.Error("error listing issues", zap.Error(err))
@ -138,7 +138,7 @@ func (p pullPalRepo) checkIssuesAndComments() error {
} }
if len(issues) == 0 { if len(issues) == 0 {
p.log.Info("no issues found") p.log.Debug("no issues found")
} else { } else {
p.log.Info("picked issue to process") p.log.Info("picked issue to process")
@ -156,7 +156,7 @@ func (p pullPalRepo) checkIssuesAndComments() error {
} }
} }
p.log.Info("checking pr comments...") p.log.Debug("checking pr comments...")
comments, err := p.ghClient.ListOpenComments(vc.ListCommentOptions{ comments, err := p.ghClient.ListOpenComments(vc.ListCommentOptions{
Handles: p.listIssueOptions.Handles, Handles: p.listIssueOptions.Handles,
}) })
@ -166,7 +166,7 @@ func (p pullPalRepo) checkIssuesAndComments() error {
} }
if len(comments) == 0 { if len(comments) == 0 {
p.log.Info("no comments found") p.log.Debug("no comments found")
} else { } else {
p.log.Info("picked comment to process") p.log.Info("picked comment to process")
@ -211,7 +211,8 @@ func (p *pullPalRepo) handleIssue(issue vc.Issue) error {
return err return err
} }
newBranchName := fmt.Sprintf("fix-%d", issue.Number) randomNumber := rand.Intn(100) + 1
newBranchName := fmt.Sprintf("fix-%d-%d", issue.Number, randomNumber)
for _, f := range changeResponse.Files { for _, f := range changeResponse.Files {
p.log.Info("replacing or adding file", zap.String("path", f.Path), zap.String("contents", f.Contents)) p.log.Info("replacing or adding file", zap.String("path", f.Path), zap.String("contents", f.Contents))
err = p.localGitClient.ReplaceOrAddLocalFile(f) err = p.localGitClient.ReplaceOrAddLocalFile(f)

View File

@ -191,8 +191,13 @@ func (gc *LocalGitClient) ReplaceOrAddLocalFile(newFile llm.File) error {
} }
fullPath := filepath.Join(gc.repo.LocalPath, newFile.Path) fullPath := filepath.Join(gc.repo.LocalPath, newFile.Path)
dirPath := filepath.Dir(fullPath)
err := os.MkdirAll(dirPath, 0755)
if err != nil {
return err
}
err := ioutil.WriteFile(fullPath, []byte(newFile.Contents), 0644) err = ioutil.WriteFile(fullPath, []byte(newFile.Contents), 0644)
if err != nil { if err != nil {
return err return err
} }