refactor: split out git client

This commit is contained in:
Marc 2024-09-01 13:31:30 -04:00
parent 2e8d188246
commit 222570b2f4
Signed by: marc
GPG key ID: 048E042F22B5DC79
3 changed files with 26 additions and 22 deletions

View file

@ -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 {

25
internal/actions/git.go Normal file
View file

@ -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")
}

View file

@ -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 {