From 222570b2f4e7b077baadd918c6b82bcc2dedc2f6 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sun, 1 Sep 2024 13:31:30 -0400 Subject: [PATCH] refactor: split out git client --- internal/actions/act.go | 21 --------------------- internal/actions/git.go | 25 +++++++++++++++++++++++++ internal/commands/configuration.go | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 internal/actions/git.go diff --git a/internal/actions/act.go b/internal/actions/act.go index cd90fbb..1b54e3c 100644 --- a/internal/actions/act.go +++ b/internal/actions/act.go @@ -3,30 +3,9 @@ package actions import ( logger "courgette/internal/logging" - "os" - "os/exec" "strings" ) -type CliClient interface { - Clone(url string, destination string) error - Exec(args ...string) error -} - -type GitClient struct{} - -func (g GitClient) Exec(args ...string) error { - cmd := exec.Command("git", args...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - return cmd.Run() -} - -func (g GitClient) Clone(url string, destination string) error { - return g.Exec("clone", url, destination, "--depth", "1") -} - // Returns a key that can be used as a directory / cache-key string // based on the provided Action repository url. func GetActionKey(url string) string { diff --git a/internal/actions/git.go b/internal/actions/git.go new file mode 100644 index 0000000..8ec614e --- /dev/null +++ b/internal/actions/git.go @@ -0,0 +1,25 @@ +// Lightweight wrapper around `git`. +package actions + +import ( + "os" + "os/exec" +) + +type CliClient interface { + Clone(url string, destination string) error +} + +type GitClient struct{} + +func (g GitClient) exec(args ...string) error { + cmd := exec.Command("git", args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + return cmd.Run() +} + +func (g GitClient) Clone(url string, destination string) error { + return g.exec("clone", url, destination, "--depth", "1") +} diff --git a/internal/commands/configuration.go b/internal/commands/configuration.go index 7bb5b29..2481ead 100644 --- a/internal/commands/configuration.go +++ b/internal/commands/configuration.go @@ -1,13 +1,13 @@ package commands import ( + metadata "courgette/metadata" "gopkg.in/yaml.v3" "io/ioutil" "os" "os/user" "path/filepath" "strings" - metadata "courgette/metadata" ) type CacheConfiguration struct {