From 7080386bbe38a5da0c5f531133b47a95ae4a8e28 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 30 Sep 2024 09:08:43 -0700 Subject: [PATCH] Extract action path list computation to a new function to reduce cyclomatic complexity Signed-off-by: Samuel Giddins --- main.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index af74ab7..44c2306 100644 --- a/main.go +++ b/main.go @@ -120,20 +120,9 @@ func initAction(ctx context.Context) (*action.FrizbeeAction, error) { cfg.Images.ExcludeTags = valToStrings(excludeTags) } - actions := os.Getenv("INPUT_ACTIONS") - actionsPaths := os.Getenv("INPUT_ACTIONS_PATHS") - if actions != "" && actionsPaths != "" { - return nil, errors.New("cannot set both INPUT_ACTIONS and INPUT_ACTIONS_PATHS") - } else if actions == "" && actionsPaths == "" { - // Default for actions was `.github/workflows`` - actions = ".github/workflows" - } - - var actionsPathList []string - if actions != "" { - actionsPathList = []string{actions} - } else { - actionsPathList = valToStrings(actionsPaths) + actionsPathList, err := actionsPathList() + if err != nil { + return nil, err } // Read the action settings from the environment and create the new frizbee replacers for actions and images @@ -193,3 +182,20 @@ func valToStrings(val string) []string { return vals } + +func actionsPathList() ([]string, error) { + actions := os.Getenv("INPUT_ACTIONS") + actionsPaths := os.Getenv("INPUT_ACTIONS_PATHS") + if actions != "" && actionsPaths != "" { + return nil, errors.New("cannot set both INPUT_ACTIONS and INPUT_ACTIONS_PATHS") + } else if actions == "" && actionsPaths == "" { + // Default for actions was `.github/workflows`` + actions = ".github/workflows" + } + + if actions != "" { + return []string{actions}, nil + } else { + return valToStrings(actionsPaths), nil + } +}