refactor: split out git client
This commit is contained in:
parent
2e8d188246
commit
222570b2f4
3 changed files with 26 additions and 22 deletions
|
@ -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
25
internal/actions/git.go
Normal 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")
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue