converted "issue ID" to issue number, and from string to int

bot should add comments when it runs into an error now
This commit is contained in:
Moby von Briesen 2023-05-12 00:06:19 -04:00
parent 7053a0b693
commit 5b143cd135
6 changed files with 35 additions and 30 deletions

View File

@ -19,11 +19,11 @@ const (
// CodeChangeRequest contains all necessary information for generating a prompt for a LLM.
type CodeChangeRequest struct {
Files []File
Subject string
Body string
IssueID string
BaseBranch string
Files []File
Subject string
Body string
IssueNumber int
BaseBranch string
}
// CodeChangeResponse contains data derived from an LLM response to a prompt generated via a CodeChangeRequest.

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strconv"
"time"
"github.com/mobyvb/pull-pal/llm"
@ -75,6 +74,12 @@ func (p *PullPal) Run() error {
if err != nil {
// TODO leave comment if error (make configurable)
p.log.Error("error handling issue", zap.Error(err))
commentText := fmt.Sprintf("I ran into a problem working on this:\n```\n%w\n```", err)
err = p.ghClient.CommentOnIssue(issue.Number, commentText)
if err != nil {
p.log.Error("error commenting on issue with error", zap.Error(err))
return err
}
}
}
@ -97,6 +102,12 @@ func (p *PullPal) Run() error {
if err != nil {
// TODO leave comment if error (make configurable)
p.log.Error("error handling comment", zap.Error(err))
commentText := fmt.Sprintf("I ran into a problem working on this:\n```\n%w\n```", err)
err = p.ghClient.RespondToComment(comment.PRNumber, comment.ID, commentText)
if err != nil {
p.log.Error("error commenting on thread with error", zap.Error(err))
return err
}
}
}
@ -107,19 +118,13 @@ func (p *PullPal) Run() error {
}
func (p *PullPal) handleIssue(issue vc.Issue) error {
issueNumber, err := strconv.Atoi(issue.ID)
if err != nil {
p.log.Error("error converting issue ID to int", zap.Error(err))
return err
}
err = p.ghClient.CommentOnIssue(issueNumber, "working on it")
err := p.ghClient.CommentOnIssue(issue.Number, "working on it")
if err != nil {
p.log.Error("error commenting on issue", zap.Error(err))
return err
}
for _, label := range p.listIssueOptions.Labels {
err = p.ghClient.RemoveLabelFromIssue(issueNumber, label)
err = p.ghClient.RemoveLabelFromIssue(issue.Number, label)
if err != nil {
p.log.Error("error removing labels from issue", zap.Error(err))
return err
@ -136,7 +141,7 @@ func (p *PullPal) handleIssue(issue vc.Issue) error {
return err
}
newBranchName := fmt.Sprintf("fix-%s", changeRequest.IssueID)
newBranchName := fmt.Sprintf("fix-%d", issue.Number)
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)
@ -145,7 +150,7 @@ func (p *PullPal) handleIssue(issue vc.Issue) error {
}
}
commitMessage := changeRequest.Subject + "\n\n" + changeResponse.Notes + "\n\nResolves: #" + changeRequest.IssueID
commitMessage := fmt.Sprintf("%s\n\n%s\n\nResolves #%d", changeRequest.Subject, changeResponse.Notes, changeRequest.IssueNumber)
p.log.Info("about to create commit", zap.String("message", commitMessage))
err = p.localGitClient.FinishCommit(commitMessage)
if err != nil {

View File

@ -82,10 +82,10 @@ func (p *PullPal) DebugLLM() error {
}
codeChangeRequest := llm.CodeChangeRequest{
Files: []llm.File{file},
Subject: "update port and add endpoint",
Body: "use port 8080 for the server in main.go. Also add an endpoint at GET /api/numbers that returns a random integer between 2 and 10",
IssueID: "1234",
Files: []llm.File{file},
Subject: "update port and add endpoint",
Body: "use port 8080 for the server in main.go. Also add an endpoint at GET /api/numbers that returns a random integer between 2 and 10",
IssueNumber: 1234,
}
p.log.Info("CODE CHANGE REQUEST", zap.String("request", codeChangeRequest.String()))

View File

@ -9,7 +9,7 @@ import (
// Issue represents an issue on a version control server.
type Issue struct {
ID string
Number int
Subject string
Body string
URL string
@ -17,7 +17,7 @@ type Issue struct {
}
func (i Issue) String() string {
return fmt.Sprintf("Issue ID: %s\nAuthor: %s\nSubject: %s\nBody:\n%s\nURL: %s\n", i.ID, i.Author.Handle, i.Subject, i.Body, i.URL)
return fmt.Sprintf("Issue #: %d\nAuthor: %s\nSubject: %s\nBody:\n%s\nURL: %s\n", i.Number, i.Author.Handle, i.Subject, i.Body, i.URL)
}
// ListIssueOptions defines options for listing issues.

View File

@ -222,7 +222,7 @@ func (gc *LocalGitClient) FinishCommit(message string) error {
// ParseIssueAndStartCommit parses the information provided in the issue to check out the appropriate branch,
// get the contents of the files mentioned in the issue, and initialize the worktree.
func (gc *LocalGitClient) ParseIssue(issue Issue) (llm.CodeChangeRequest, error) {
func (gc *LocalGitClient) ParseIssueAndStartCommit(issue Issue) (llm.CodeChangeRequest, error) {
var changeRequest llm.CodeChangeRequest
if gc.worktree != nil {
@ -253,10 +253,10 @@ func (gc *LocalGitClient) ParseIssue(issue Issue) (llm.CodeChangeRequest, error)
}
return llm.CodeChangeRequest{
Subject: issue.Subject,
Body: issueBody.PromptBody,
IssueID: issue.ID,
Files: files,
BaseBranch: issueBody.BaseBranch,
Subject: issue.Subject,
Body: issueBody.PromptBody,
IssueNumber: issue.Number,
Files: files,
BaseBranch: issueBody.BaseBranch,
}, nil
}

View File

@ -57,7 +57,7 @@ func (gc *GithubClient) OpenCodeChangeRequest(req llm.CodeChangeRequest, res llm
}
body := res.Notes
body += fmt.Sprintf("\n\nResolves #%s", req.IssueID)
body += fmt.Sprintf("\n\nResolves #%d", req.IssueNumber)
// Finally, open a pull request from the new branch.
pr, _, err := gc.client.PullRequests.Create(gc.ctx, gc.repo.Owner.Handle, gc.repo.Name, &github.NewPullRequest{
@ -102,7 +102,7 @@ func (gc *GithubClient) ListOpenIssues(options ListIssueOptions) ([]Issue, error
}
nextIssue := Issue{
ID: strconv.Itoa(issue.GetNumber()),
Number: issue.GetNumber(),
Subject: issue.GetTitle(),
Body: issue.GetBody(),
URL: issue.GetHTMLURL(),