diff --git a/git/clone.go b/git/clone.go index a98034f..f94e954 100644 --- a/git/clone.go +++ b/git/clone.go @@ -2,38 +2,38 @@ package git import ( "fmt" + "os" - "github.com/thegeeklab/wp-plugin-go/v2/types" - "golang.org/x/sys/execabs" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) // FetchSource fetches the source from remote. -func (r *Repository) FetchSource() *types.Cmd { +func (r *Repository) FetchSource() *plugin_exec.Cmd { args := []string{ "fetch", "origin", fmt.Sprintf("+%s:", r.Branch), } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd } // CheckoutHead handles branch checkout. -func (r *Repository) CheckoutHead() *types.Cmd { +func (r *Repository) CheckoutHead() *plugin_exec.Cmd { args := []string{ "checkout", "-qf", r.Branch, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd diff --git a/git/commit.go b/git/commit.go index 31e008e..5e58bc7 100644 --- a/git/commit.go +++ b/git/commit.go @@ -1,28 +1,23 @@ package git import ( - "io" + "os" - "github.com/thegeeklab/wp-plugin-go/v2/types" - "golang.org/x/sys/execabs" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) // Add updates the index to match the working tree. -func (r *Repository) Add() *types.Cmd { - cmd := &types.Cmd{ - Cmd: execabs.Command( - gitBin, - "add", - "--all", - ), - } +func (r *Repository) Add() *plugin_exec.Cmd { + cmd := plugin_exec.Command(gitBin, "add", "--all") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd } // IsCleanTree returns non-zero if diff between index and local repository. -func (r *Repository) IsCleanTree() *types.Cmd { +func (r *Repository) IsCleanTree() *plugin_exec.Cmd { args := []string{ "diff-index", "--quiet", @@ -30,19 +25,15 @@ func (r *Repository) IsCleanTree() *types.Cmd { "--ignore-submodules", } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) cmd.Dir = r.WorkDir - cmd.Stdout = io.Discard - cmd.Stderr = io.Discard - cmd.SetTrace(false) + cmd.Trace = false return cmd } // Commit creates a new commit with the specified commit message. -func (r *Repository) Commit() *types.Cmd { +func (r *Repository) Commit() *plugin_exec.Cmd { args := []string{ "commit", "-m", @@ -57,9 +48,9 @@ func (r *Repository) Commit() *types.Cmd { args = append(args, "--no-verify") } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd diff --git a/git/config.go b/git/config.go index 9ccbc36..ef29aa8 100644 --- a/git/config.go +++ b/git/config.go @@ -3,13 +3,12 @@ package git import ( "strconv" - "github.com/thegeeklab/wp-plugin-go/v2/types" - "golang.org/x/sys/execabs" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) // ConfigAutocorrect sets the local git autocorrect configuration for the given repository. // The autocorrect setting determines how git handles minor typos in commands. -func (r *Repository) ConfigAutocorrect() *types.Cmd { +func (r *Repository) ConfigAutocorrect() *plugin_exec.Cmd { args := []string{ "config", "--local", @@ -17,17 +16,15 @@ func (r *Repository) ConfigAutocorrect() *types.Cmd { r.Autocorrect, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) cmd.Dir = r.WorkDir - cmd.SetTrace(false) + cmd.Trace = false return cmd } // ConfigUserEmail sets the global git author email. -func (r *Repository) ConfigUserEmail() *types.Cmd { +func (r *Repository) ConfigUserEmail() *plugin_exec.Cmd { args := []string{ "config", "--local", @@ -35,17 +32,15 @@ func (r *Repository) ConfigUserEmail() *types.Cmd { r.Author.Email, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) cmd.Dir = r.WorkDir - cmd.SetTrace(false) + cmd.Trace = false return cmd } // ConfigUserName configures the user.name git config setting for the given repository. -func (r *Repository) ConfigUserName() *types.Cmd { +func (r *Repository) ConfigUserName() *plugin_exec.Cmd { args := []string{ "config", "--local", @@ -53,17 +48,15 @@ func (r *Repository) ConfigUserName() *types.Cmd { r.Author.Name, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) cmd.Dir = r.WorkDir - cmd.SetTrace(false) + cmd.Trace = false return cmd } // ConfigSSLVerify configures the http.sslVerify git config setting for the given repository. -func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd { +func (r *Repository) ConfigSSLVerify(skipVerify bool) *plugin_exec.Cmd { args := []string{ "config", "--local", @@ -71,17 +64,15 @@ func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd { strconv.FormatBool(!skipVerify), } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) cmd.Dir = r.WorkDir - cmd.SetTrace(false) + cmd.Trace = false return cmd } // ConfigSSHCommand sets custom SSH key. -func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd { +func (r *Repository) ConfigSSHCommand(sshKey string) *plugin_exec.Cmd { args := []string{ "config", "--local", @@ -89,11 +80,9 @@ func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd { "ssh -i " + sshKey, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) cmd.Dir = r.WorkDir - cmd.SetTrace(false) + cmd.Trace = false return cmd } diff --git a/git/init.go b/git/init.go index 81f461d..32e4740 100644 --- a/git/init.go +++ b/git/init.go @@ -1,21 +1,22 @@ package git import ( - "github.com/thegeeklab/wp-plugin-go/v2/types" - "golang.org/x/sys/execabs" + "os" + + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) // Init creates a new Git repository in the specified directory. -func (r *Repository) Init() *types.Cmd { +func (r *Repository) Init() *plugin_exec.Cmd { args := []string{ "init", "-b", r.Branch, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd diff --git a/git/remote.go b/git/remote.go index 59c4d68..14391e6 100644 --- a/git/remote.go +++ b/git/remote.go @@ -2,29 +2,29 @@ package git import ( "fmt" + "os" - "github.com/thegeeklab/wp-plugin-go/v2/types" - "golang.org/x/sys/execabs" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) // RemoteRemove drops the defined remote from a git repo. -func (r *Repository) RemoteRemove() *types.Cmd { +func (r *Repository) RemoteRemove() *plugin_exec.Cmd { args := []string{ "remote", "rm", r.RemoteName, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd } // RemoteAdd adds an additional remote to a git repo. -func (r *Repository) RemoteAdd() *types.Cmd { +func (r *Repository) RemoteAdd() *plugin_exec.Cmd { args := []string{ "remote", "add", @@ -32,16 +32,16 @@ func (r *Repository) RemoteAdd() *types.Cmd { r.RemoteURL, } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd } // RemotePush pushs the changes from the local head to a remote branch. -func (r *Repository) RemotePush() *types.Cmd { +func (r *Repository) RemotePush() *plugin_exec.Cmd { args := []string{ "push", r.RemoteName, @@ -56,9 +56,9 @@ func (r *Repository) RemotePush() *types.Cmd { args = append(args, "--follow-tags") } - cmd := &types.Cmd{ - Cmd: execabs.Command(gitBin, args...), - } + cmd := plugin_exec.Command(gitBin, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = r.WorkDir return cmd diff --git a/go.mod b/go.mod index bc85703..0faa59b 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,8 @@ go 1.22 require ( github.com/rs/zerolog v1.32.0 github.com/stretchr/testify v1.9.0 - github.com/thegeeklab/wp-plugin-go/v2 v2.3.1 + github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 github.com/urfave/cli/v2 v2.27.2 - golang.org/x/sys v0.20.0 ) require ( @@ -31,5 +30,6 @@ require ( github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index fe88f2d..fc9acb5 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/thegeeklab/wp-plugin-go/v2 v2.3.1 h1:ARwYgTPZ5iPsmOenmqcCf8TjiEe8wBOHKO7H/Xshe48= -github.com/thegeeklab/wp-plugin-go/v2 v2.3.1/go.mod h1:0t8M8txtEFiaB6RqLX8vLrxkqAo5FT5Hx7dztN592D4= +github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 h1:Mv5i8S1WY+BUNjTjX6lOnB3p8S9mvM+XwfY4R98gx0g= +github.com/thegeeklab/wp-plugin-go/v3 v3.0.2/go.mod h1:ij1iJcAVgzerBTqXnmq0bu1VA+hhVVwzXKqiqfoGjjg= github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= diff --git a/internal/doc/main.go b/internal/doc/main.go index 6d52a9d..dac26e4 100644 --- a/internal/doc/main.go +++ b/internal/doc/main.go @@ -11,8 +11,8 @@ import ( "time" "github.com/thegeeklab/wp-git-action/plugin" - "github.com/thegeeklab/wp-plugin-go/v2/docs" - "github.com/thegeeklab/wp-plugin-go/v2/template" + plugin_docs "github.com/thegeeklab/wp-plugin-go/v3/docs" + plugin_template "github.com/thegeeklab/wp-plugin-go/v3/template" ) func main() { @@ -23,7 +23,7 @@ func main() { p := plugin.New(nil) - out, err := template.Render(context.Background(), client, tmpl, docs.GetTemplateData(p.App)) + out, err := plugin_template.Render(context.Background(), client, tmpl, plugin_docs.GetTemplateData(p.App)) if err != nil { panic(err) } diff --git a/plugin/impl.go b/plugin/impl.go index 9b6e5b0..4125c9d 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -9,9 +9,9 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/thegeeklab/wp-plugin-go/v2/file" - "github.com/thegeeklab/wp-plugin-go/v2/types" - "github.com/thegeeklab/wp-plugin-go/v2/util" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" + plugin_file "github.com/thegeeklab/wp-plugin-go/v3/file" + plugin_util "github.com/thegeeklab/wp-plugin-go/v3/util" ) var ( @@ -106,8 +106,8 @@ func (p *Plugin) Validate() error { func (p *Plugin) Execute() error { var err error - homeDir := util.GetUserHomeDir() - batchCmd := make([]*types.Cmd, 0) + homeDir := plugin_util.GetUserHomeDir() + batchCmd := make([]*plugin_exec.Cmd, 0) gitEnv := []string{ "GIT_AUTHOR_NAME", "GIT_AUTHOR_EMAIL", @@ -143,12 +143,12 @@ func (p *Plugin) Execute() error { } defer os.RemoveAll(p.Settings.Repo.WorkDir) - p.Settings.Repo.IsEmpty, err = file.IsDirEmpty(p.Settings.Repo.WorkDir) + p.Settings.Repo.IsEmpty, err = plugin_file.IsDirEmpty(p.Settings.Repo.WorkDir) if err != nil { return fmt.Errorf("failed to check working directory: %w", err) } - isDir, err := file.IsDir(filepath.Join(p.Settings.Repo.WorkDir, ".git")) + isDir, err := plugin_file.IsDir(filepath.Join(p.Settings.Repo.WorkDir, ".git")) if err != nil { return fmt.Errorf("failed to check working directory: %w", err) } @@ -215,7 +215,7 @@ func (p *Plugin) Execute() error { // handleClone clones the remote repository into the configured working directory. // If the working directory is not empty, it returns an error. func (p *Plugin) handleClone() error { - var batchCmd []*types.Cmd + var batchCmd []*plugin_exec.Cmd if !p.Settings.Repo.IsEmpty { return fmt.Errorf("%w: %s exists and not empty", ErrGitCloneDestintionNotValid, p.Settings.Repo.WorkDir) diff --git a/plugin/plugin.go b/plugin/plugin.go index 79eeca1..609a434 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/thegeeklab/wp-git-action/git" - wp "github.com/thegeeklab/wp-plugin-go/v2/plugin" + plugin_base "github.com/thegeeklab/wp-plugin-go/v3/plugin" "github.com/urfave/cli/v2" ) @@ -12,7 +12,7 @@ import ( // Plugin implements provide the plugin. type Plugin struct { - *wp.Plugin + *plugin_base.Plugin Settings *Settings } @@ -40,15 +40,15 @@ type Pages struct { type GitAction string -func New(e wp.ExecuteFunc, build ...string) *Plugin { +func New(e plugin_base.ExecuteFunc, build ...string) *Plugin { p := &Plugin{ Settings: &Settings{}, } - options := wp.Options{ + options := plugin_base.Options{ Name: "wp-git-action", Description: "Perform git actions", - Flags: Flags(p.Settings, wp.FlagsPluginCategory), + Flags: Flags(p.Settings, plugin_base.FlagsPluginCategory), Execute: p.run, HideWoodpeckerFlags: true, } @@ -65,7 +65,7 @@ func New(e wp.ExecuteFunc, build ...string) *Plugin { options.Execute = e } - p.Plugin = wp.New(options) + p.Plugin = plugin_base.New(options) return p } diff --git a/plugin/rsync.go b/plugin/rsync.go index 820e5fb..9923fe8 100644 --- a/plugin/rsync.go +++ b/plugin/rsync.go @@ -1,12 +1,12 @@ package plugin import ( - "github.com/thegeeklab/wp-plugin-go/v2/types" + "os" - "golang.org/x/sys/execabs" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) -func SyncDirectories(exclude []string, del bool, src, dest string, debug bool) *types.Cmd { +func SyncDirectories(exclude []string, del bool, src, dest string, debug bool) *plugin_exec.Cmd { args := []string{ "-r", "--exclude", @@ -41,9 +41,9 @@ func SyncDirectories(exclude []string, del bool, src, dest string, debug bool) * dest, ) - cmd := &types.Cmd{ - Cmd: execabs.Command("rsync", args...), - } + cmd := plugin_exec.Command("rsync", args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr cmd.Dir = src return cmd diff --git a/plugin/util.go b/plugin/util.go index 9fe48c9..9f92dc3 100644 --- a/plugin/util.go +++ b/plugin/util.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/thegeeklab/wp-plugin-go/v2/types" + plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec" ) const ( @@ -30,7 +30,7 @@ func WriteNetrc(path, machine, login, password string) error { } // ExecBatch executes a batch of commands. If any command in the batch fails, the function will return the error. -func ExecBatch(batchCmd []*types.Cmd) error { +func ExecBatch(batchCmd []*plugin_exec.Cmd) error { for _, cmd := range batchCmd { if cmd == nil { continue