From dfef07a1c020275f4448034ea7b707a9fabc6b9c Mon Sep 17 00:00:00 2001 From: Moby von Briesen Date: Mon, 15 May 2023 19:23:36 -0400 Subject: [PATCH] some changes make some unnecessary logging debug logs add some randomness into branch name create directories as necessary if they don't exist --- llm/prompts/comment-diff-request.tmpl | 6 ++++-- pullpal/common.go | 13 +++++++------ vc/git.go | 7 ++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/llm/prompts/comment-diff-request.tmpl b/llm/prompts/comment-diff-request.tmpl index 604d54a..9499023 100644 --- a/llm/prompts/comment-diff-request.tmpl +++ b/llm/prompts/comment-diff-request.tmpl @@ -6,7 +6,9 @@ File: ``` Diff: +``` {{ .Diff }} +``` Comment: {{ .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. 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 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 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", starting with "R". Response Template A: Q diff --git a/pullpal/common.go b/pullpal/common.go index b694edc..81555ca 100644 --- a/pullpal/common.go +++ b/pullpal/common.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/rand" "path/filepath" "strings" "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) ppRepos := []pullPalRepo{} - fmt.Println("asdfasfdasfasdfasdf") for _, r := range cfg.Repos { fmt.Println(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. func (p pullPalRepo) checkIssuesAndComments() error { - p.log.Info("checking github issues...") + p.log.Debug("checking github issues...") issues, err := p.ghClient.ListOpenIssues(p.listIssueOptions) if err != nil { p.log.Error("error listing issues", zap.Error(err)) @@ -138,7 +138,7 @@ func (p pullPalRepo) checkIssuesAndComments() error { } if len(issues) == 0 { - p.log.Info("no issues found") + p.log.Debug("no issues found") } else { 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{ Handles: p.listIssueOptions.Handles, }) @@ -166,7 +166,7 @@ func (p pullPalRepo) checkIssuesAndComments() error { } if len(comments) == 0 { - p.log.Info("no comments found") + p.log.Debug("no comments found") } else { p.log.Info("picked comment to process") @@ -211,7 +211,8 @@ func (p *pullPalRepo) handleIssue(issue vc.Issue) error { 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 { p.log.Info("replacing or adding file", zap.String("path", f.Path), zap.String("contents", f.Contents)) err = p.localGitClient.ReplaceOrAddLocalFile(f) diff --git a/vc/git.go b/vc/git.go index f776652..dcff668 100644 --- a/vc/git.go +++ b/vc/git.go @@ -191,8 +191,13 @@ func (gc *LocalGitClient) ReplaceOrAddLocalFile(newFile llm.File) error { } 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 { return err }