Create "local git client" and "openai client"

OpenAIClient can be used to interact with OpenAI's API. Untested at the
moment (except with an API key that does not yet have perms)
Local git client splits the "git" functionality (e.g. make commits,
checkout branches, etc...) away from the "github" client

I also removed a lot of duplicate code for the different commands in cmd
And created a basic "local issue" command to send a "code change
request" to the llm, and receive a code change response. Eventually, I
want this to make the corresponding local git changes, for the user to
check.

TODO: github client should only be responsible for github-specific
actions, e.g. opening a PR or listing issues/comments
This commit is contained in:
Moby von Briesen
2023-04-25 20:32:08 -04:00
parent 726e34d093
commit 10c77854a9
9 changed files with 363 additions and 68 deletions

View File

@@ -3,11 +3,7 @@ package cmd
import (
"fmt"
"github.com/mobyvb/pull-pal/pullpal"
"github.com/mobyvb/pull-pal/vc"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var listCommentsCmd = &cobra.Command{
@@ -18,22 +14,7 @@ var listCommentsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cfg := getConfig()
log := zap.L()
author := vc.Author{
Email: cfg.selfEmail,
Handle: cfg.selfHandle,
Token: cfg.githubToken,
}
repo := vc.Repository{
LocalPath: cfg.localRepoPath,
HostDomain: cfg.repoDomain,
Name: cfg.repoName,
Owner: vc.Author{
Handle: cfg.repoHandle,
},
}
p, err := pullpal.NewPullPal(cmd.Context(), log.Named("pullpal"), author, repo)
p, err := getPullPal(cmd.Context(), cfg)
if err != nil {
fmt.Println("error creating new pull pal", err)
return

View File

@@ -3,11 +3,7 @@ package cmd
import (
"fmt"
"github.com/mobyvb/pull-pal/pullpal"
"github.com/mobyvb/pull-pal/vc"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var listIssuesCmd = &cobra.Command{
@@ -16,24 +12,8 @@ var listIssuesCmd = &cobra.Command{
Long: "Lists github issues meeting the configured criteria",
Run: func(cmd *cobra.Command, args []string) {
cfg := getConfig()
fmt.Println("list issues called")
log := zap.L()
author := vc.Author{
Email: cfg.selfEmail,
Handle: cfg.selfHandle,
Token: cfg.githubToken,
}
repo := vc.Repository{
LocalPath: cfg.localRepoPath,
HostDomain: cfg.repoDomain,
Name: cfg.repoName,
Owner: vc.Author{
Handle: cfg.repoHandle,
},
}
p, err := pullpal.NewPullPal(cmd.Context(), log.Named("pullpal"), author, repo)
p, err := getPullPal(cmd.Context(), cfg)
if err != nil {
fmt.Println("error creating new pull pal", err)
return

43
cmd/local-issue.go Normal file
View File

@@ -0,0 +1,43 @@
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)
}

View File

@@ -1,6 +1,7 @@
package cmd
import (
"context"
"errors"
"fmt"
"os"
@@ -8,10 +9,10 @@ import (
"github.com/mobyvb/pull-pal/llm"
"github.com/mobyvb/pull-pal/pullpal"
"github.com/mobyvb/pull-pal/vc"
"go.uber.org/zap"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
)
// todo: some of this config definition/usage can be moved to other packages
@@ -20,6 +21,7 @@ type config struct {
selfHandle string
selfEmail string
githubToken string
openAIToken string
// remote repo info
repoDomain string
@@ -42,6 +44,7 @@ func getConfig() config {
selfHandle: viper.GetString("handle"),
selfEmail: viper.GetString("email"),
githubToken: viper.GetString("github-token"),
openAIToken: viper.GetString("open-ai-token"),
repoDomain: viper.GetString("repo-domain"),
repoHandle: viper.GetString("repo-handle"),
@@ -57,6 +60,33 @@ func getConfig() config {
}
}
func getPullPal(ctx context.Context, cfg config) (*pullpal.PullPal, error) {
/*
log, err := zap.NewProduction()
if err != nil {
panic(err)
}
*/
log := zap.L()
author := vc.Author{
Email: cfg.selfEmail,
Handle: cfg.selfHandle,
Token: cfg.githubToken,
}
repo := vc.Repository{
LocalPath: cfg.localRepoPath,
HostDomain: cfg.repoDomain,
Name: cfg.repoName,
Owner: vc.Author{
Handle: cfg.repoHandle,
},
}
p, err := pullpal.NewPullPal(ctx, log.Named("pullpal"), author, repo, cfg.openAIToken)
return p, err
}
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "pull-pal",
@@ -72,29 +102,7 @@ It can be used to:
Run: func(cmd *cobra.Command, args []string) {
cfg := getConfig()
/*
log, err := zap.NewProduction()
if err != nil {
panic(err)
}
*/
log := zap.L()
author := vc.Author{
Email: cfg.selfEmail,
Handle: cfg.selfHandle,
Token: cfg.githubToken,
}
repo := vc.Repository{
LocalPath: cfg.localRepoPath,
HostDomain: cfg.repoDomain,
Name: cfg.repoName,
Owner: vc.Author{
Handle: cfg.repoHandle,
},
}
p, err := pullpal.NewPullPal(cmd.Context(), log.Named("pullpal"), author, repo)
p, err := getPullPal(cmd.Context(), cfg)
if err != nil {
fmt.Println("error creating new pull pal", err)
return
@@ -188,6 +196,7 @@ func init() {
rootCmd.PersistentFlags().StringP("handle", "u", "HANDLE", "handle to use for version control actions")
rootCmd.PersistentFlags().StringP("email", "e", "EMAIL", "email to use for version control actions")
rootCmd.PersistentFlags().StringP("github-token", "t", "GITHUB TOKEN", "token for authenticating Github actions")
rootCmd.PersistentFlags().StringP("open-ai-token", "k", "OPENAI TOKEN", "token for authenticating OpenAI")
rootCmd.PersistentFlags().StringP("repo-domain", "d", "github.com", "domain for version control server")
rootCmd.PersistentFlags().StringP("repo-handle", "o", "REPO-HANDLE", "handle of repository's owner on version control server")
@@ -204,6 +213,7 @@ func init() {
viper.BindPFlag("handle", rootCmd.PersistentFlags().Lookup("handle"))
viper.BindPFlag("email", rootCmd.PersistentFlags().Lookup("email"))
viper.BindPFlag("github-token", rootCmd.PersistentFlags().Lookup("github-token"))
viper.BindPFlag("open-ai-token", rootCmd.PersistentFlags().Lookup("open-ai-token"))
viper.BindPFlag("repo-domain", rootCmd.PersistentFlags().Lookup("repo-domain"))
viper.BindPFlag("repo-handle", rootCmd.PersistentFlags().Lookup("repo-handle"))