From 7466ad21a9f0f3cca42daf059949b7c964e01e50 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sun, 1 Sep 2024 13:38:53 -0400 Subject: [PATCH] refactor: pull actions as actions manager --- internal/actions/act.go | 11 ----------- internal/actions/manager.go | 25 +++++++++++++++++++++++++ internal/runner/runner.go | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 internal/actions/manager.go diff --git a/internal/actions/act.go b/internal/actions/act.go index 1b54e3c..bac66e5 100644 --- a/internal/actions/act.go +++ b/internal/actions/act.go @@ -2,7 +2,6 @@ package actions import ( - logger "courgette/internal/logging" "strings" ) @@ -21,13 +20,3 @@ func GetActionKey(url string) string { return strings.Join(parts, "__") } - -// Prefetches and caches the action defined by at . -// -// is expected to be the full url of the repository where -// the action lives. -func PrefetchAction(client CliClient, actionName string, destination string) error { - logger.Info("Prefetching action: %s to %s", actionName, destination) - - return client.Clone(actionName, destination) -} diff --git a/internal/actions/manager.go b/internal/actions/manager.go new file mode 100644 index 0000000..24cf2d6 --- /dev/null +++ b/internal/actions/manager.go @@ -0,0 +1,25 @@ +package actions + +import ( + logger "courgette/internal/logging" +) + +type ActionsManager struct { + git CliClient +} + +func NewActionsManager() ActionsManager { + return ActionsManager{ + git: GitClient{}, + } +} + +// Prefetches and caches the action defined by at . +// +// is expected to be the full url of the repository where +// the action lives. +func (a ActionsManager) PrefetchAction(actionName string, destination string) error { + logger.Info("Prefetching action: %s to %s", actionName, destination) + + return a.git.Clone(actionName, destination) +} diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 50b195a..2a2937f 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -49,7 +49,7 @@ func (r *Runner) RunWorkflow(workflow workflows.Workflow) TaskTracker { switch n.(type) { case workflows.Step: if useAction := n.(workflows.Step).Use; useAction != "" { - actions.PrefetchAction(actions.GitClient{}, useAction, r.Cache.Path(actions.GetActionKey(useAction))) + actions.NewActionsManager().PrefetchAction(useAction, r.Cache.Path(actions.GetActionKey(useAction))) } } })