mirror of
https://github.com/Pull-Pal/pull-pal.git
synced 2026-04-18 11:39:09 -04:00
cleanup/refactor (#1)
focus on fully automated as basic/default functionality. remove unnecessary commands except for local git debug. remove unnecessary interfaces and code. remove local git functionality from github client. probably some other stuff too
This commit is contained in:
committed by
GitHub
parent
3a312b2b9b
commit
cbec4c1be9
@@ -6,9 +6,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "Runs a fully automated pull pal service",
|
||||
var debugGitCmd = &cobra.Command{
|
||||
Use: "debug-git",
|
||||
Short: "debug git functionality",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cfg := getConfig()
|
||||
|
||||
@@ -19,14 +19,14 @@ var runCmd = &cobra.Command{
|
||||
}
|
||||
fmt.Println("Successfully initialized pull pal")
|
||||
|
||||
err = p.Run()
|
||||
err = p.DebugGit()
|
||||
if err != nil {
|
||||
fmt.Println("error running", err)
|
||||
fmt.Println("err debugging git", err)
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(runCmd)
|
||||
rootCmd.AddCommand(debugGitCmd)
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listCommentsCmd = &cobra.Command{
|
||||
Use: "list-comments",
|
||||
Short: "Lists comments on a Github PR meeting the configured criteria",
|
||||
Long: "Lists comments on a Github PR meeting the configured criteria",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cfg := getConfig()
|
||||
|
||||
p, err := getPullPal(cmd.Context(), cfg)
|
||||
if err != nil {
|
||||
fmt.Println("error creating new pull pal", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Successfully initialized pull pal")
|
||||
|
||||
prID := args[0]
|
||||
issueList, err := p.ListComments(prID, cfg.usersToListenTo)
|
||||
if err != nil {
|
||||
fmt.Println("error listing issues", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(issueList)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(listCommentsCmd)
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listIssuesCmd = &cobra.Command{
|
||||
Use: "list-issues",
|
||||
Short: "Lists github issues meeting the configured criteria",
|
||||
Long: "Lists github issues meeting the configured criteria",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cfg := getConfig()
|
||||
|
||||
p, err := getPullPal(cmd.Context(), cfg)
|
||||
if err != nil {
|
||||
fmt.Println("error creating new pull pal", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Successfully initialized pull pal")
|
||||
|
||||
issueList, err := p.ListIssues(cfg.usersToListenTo, cfg.requiredIssueLabels)
|
||||
if err != nil {
|
||||
fmt.Println("error listing issues", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(issueList)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(listIssuesCmd)
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mobyvb/pull-pal/vc"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var localIssueCmd = &cobra.Command{
|
||||
Use: "local-issue",
|
||||
Short: "Processes a locally-defined/provided issue rather than remotely reading one from the Github repo",
|
||||
// TODO csv filepath as arg?
|
||||
// Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cfg := getConfig()
|
||||
|
||||
p, err := getPullPal(cmd.Context(), cfg)
|
||||
if err != nil {
|
||||
fmt.Println("error creating new pull pal", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Successfully initialized pull pal")
|
||||
|
||||
newIssue := vc.Issue{
|
||||
Subject: "a few updates",
|
||||
Body: "Add a quote from Frodo to the README.md and index.html files.\nSwitch main.go to port 7777.\nFiles:index.html,README.md,main.go",
|
||||
Author: vc.Author{
|
||||
Handle: "mobyvb",
|
||||
},
|
||||
}
|
||||
err = p.MakeLocalChange(newIssue)
|
||||
if err != nil {
|
||||
fmt.Println("err making local change", err)
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(localIssueCmd)
|
||||
}
|
||||
87
cmd/root.go
87
cmd/root.go
@@ -2,11 +2,9 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mobyvb/pull-pal/llm"
|
||||
"github.com/mobyvb/pull-pal/pullpal"
|
||||
"github.com/mobyvb/pull-pal/vc"
|
||||
"go.uber.org/zap"
|
||||
@@ -30,8 +28,6 @@ type config struct {
|
||||
|
||||
// local paths
|
||||
localRepoPath string
|
||||
promptPath string
|
||||
responsePath string
|
||||
|
||||
// program settings
|
||||
promptToClipboard bool
|
||||
@@ -51,8 +47,6 @@ func getConfig() config {
|
||||
repoName: viper.GetString("repo-name"),
|
||||
|
||||
localRepoPath: viper.GetString("local-repo-path"),
|
||||
promptPath: viper.GetString("prompt-path"),
|
||||
responsePath: viper.GetString("response-path"),
|
||||
|
||||
promptToClipboard: viper.GetBool("prompt-to-clipboard"),
|
||||
usersToListenTo: viper.GetStringSlice("users-to-listen-to"),
|
||||
@@ -61,6 +55,7 @@ func getConfig() config {
|
||||
}
|
||||
|
||||
func getPullPal(ctx context.Context, cfg config) (*pullpal.PullPal, error) {
|
||||
// TODO figure out debug logging
|
||||
log, err := zap.NewProduction()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -91,16 +86,7 @@ func getPullPal(ctx context.Context, cfg config) (*pullpal.PullPal, error) {
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "pull-pal",
|
||||
Short: "A bot that uses large language models to act as a collaborator on a git project",
|
||||
Long: `A bot that uses large language models to act as a collaborator on a git project.
|
||||
|
||||
It can be used to:
|
||||
* Monitor a repository for open issues, and generate LLM prompts according to the issue details
|
||||
* Read an LLM response and process it into a new git commit and code change request on the version control server
|
||||
`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
Short: "run an automated digital assitant to monitor and make code changes to a github repository",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cfg := getConfig()
|
||||
|
||||
@@ -111,64 +97,11 @@ It can be used to:
|
||||
}
|
||||
fmt.Println("Successfully initialized pull pal")
|
||||
|
||||
// TODO this loop breaks on the second iteration due to a weird git state or something
|
||||
for {
|
||||
var input string
|
||||
fmt.Println("Press 'enter' when ready to select issue. Type 'exit' to exit.")
|
||||
fmt.Scanln(&input)
|
||||
if input == "exit" {
|
||||
break
|
||||
}
|
||||
|
||||
var issue vc.Issue
|
||||
var changeRequest llm.CodeChangeRequest
|
||||
if cfg.promptToClipboard {
|
||||
issue, changeRequest, err = p.PickIssueToClipboard()
|
||||
if err != nil {
|
||||
if !errors.Is(err, pullpal.IssueNotFound) {
|
||||
fmt.Println("error selecting issue and/or generating prompt", err)
|
||||
return
|
||||
} else {
|
||||
fmt.Println("No issues found. Proceeding to parse prompt")
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Picked issue and copied prompt to clipboard. Issue #%s\n", issue.ID)
|
||||
}
|
||||
} else {
|
||||
issue, changeRequest, err = p.PickIssueToFile(cfg.promptPath)
|
||||
if err != nil {
|
||||
if !errors.Is(err, pullpal.IssueNotFound) {
|
||||
fmt.Println("error selecting issue and/or generating prompt", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("No issues found. Proceeding to parse prompt")
|
||||
} else {
|
||||
fmt.Printf("Picked issue and copied prompt to clipboard. Issue #%s. Prompt location %s\n", issue.ID, cfg.promptPath)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("\nInsert LLM response into response file: %s", cfg.responsePath)
|
||||
|
||||
fmt.Println("Press 'enter' when ready to parse response. Enter 'skip' to skip response parsing. Enter 'exit' to exit.")
|
||||
fmt.Scanln(&input)
|
||||
if input == "exit" {
|
||||
break
|
||||
}
|
||||
if input == "skip" {
|
||||
fmt.Println()
|
||||
continue
|
||||
}
|
||||
|
||||
prURL, err := p.ProcessResponseFromFile(changeRequest, cfg.responsePath)
|
||||
if err != nil {
|
||||
fmt.Println("error parsing LLM response and/or making version control changes", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Successfully opened a code change request. Link: %s\n", prURL)
|
||||
err = p.Run()
|
||||
if err != nil {
|
||||
fmt.Println("error running", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Done. Thank you!")
|
||||
},
|
||||
}
|
||||
|
||||
@@ -198,11 +131,8 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringP("repo-handle", "o", "REPO-HANDLE", "handle of repository's owner on version control server")
|
||||
rootCmd.PersistentFlags().StringP("repo-name", "n", "REPO-NAME", "name of repository on version control server")
|
||||
|
||||
rootCmd.PersistentFlags().StringP("local-repo-path", "l", "/tmp/pullpalrepo/", "path where pull pal will check out a local copy of the repository")
|
||||
rootCmd.PersistentFlags().StringP("prompt-path", "p", "./path/to/prompt.txt", "path where pull pal will write the llm prompt")
|
||||
rootCmd.PersistentFlags().StringP("response-path", "r", "./path/to/response.txt", "path where pull pal will read the llm response from")
|
||||
rootCmd.PersistentFlags().StringP("local-repo-path", "l", "/tmp/pullpallrepo", "local path to check out ephemeral repository in")
|
||||
|
||||
rootCmd.PersistentFlags().BoolP("prompt-to-clipboard", "c", false, "whether to copy LLM prompt to clipboard rather than using a file")
|
||||
rootCmd.PersistentFlags().StringSliceP("users-to-listen-to", "a", []string{}, "a list of Github users that Pull Pal will respond to")
|
||||
rootCmd.PersistentFlags().StringSliceP("required-issue-labels", "i", []string{}, "a list of labels that are required for Pull Pal to select an issue")
|
||||
|
||||
@@ -216,10 +146,7 @@ func init() {
|
||||
viper.BindPFlag("repo-name", rootCmd.PersistentFlags().Lookup("repo-name"))
|
||||
|
||||
viper.BindPFlag("local-repo-path", rootCmd.PersistentFlags().Lookup("local-repo-path"))
|
||||
viper.BindPFlag("prompt-path", rootCmd.PersistentFlags().Lookup("prompt-path"))
|
||||
viper.BindPFlag("response-path", rootCmd.PersistentFlags().Lookup("response-path"))
|
||||
|
||||
viper.BindPFlag("prompt-to-clipboard", rootCmd.PersistentFlags().Lookup("prompt-to-clipboard"))
|
||||
viper.BindPFlag("users-to-listen-to", rootCmd.PersistentFlags().Lookup("users-to-listen-to"))
|
||||
viper.BindPFlag("required-issue-labels", rootCmd.PersistentFlags().Lookup("required-issue-labels"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user