Skip to content

Commit 7080386

Browse files
committed
Extract action path list computation to a new function to reduce cyclomatic complexity
Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
1 parent b5a8a46 commit 7080386

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

main.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,9 @@ func initAction(ctx context.Context) (*action.FrizbeeAction, error) {
120120
cfg.Images.ExcludeTags = valToStrings(excludeTags)
121121
}
122122

123-
actions := os.Getenv("INPUT_ACTIONS")
124-
actionsPaths := os.Getenv("INPUT_ACTIONS_PATHS")
125-
if actions != "" && actionsPaths != "" {
126-
return nil, errors.New("cannot set both INPUT_ACTIONS and INPUT_ACTIONS_PATHS")
127-
} else if actions == "" && actionsPaths == "" {
128-
// Default for actions was `.github/workflows``
129-
actions = ".github/workflows"
130-
}
131-
132-
var actionsPathList []string
133-
if actions != "" {
134-
actionsPathList = []string{actions}
135-
} else {
136-
actionsPathList = valToStrings(actionsPaths)
123+
actionsPathList, err := actionsPathList()
124+
if err != nil {
125+
return nil, err
137126
}
138127

139128
// 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 {
193182

194183
return vals
195184
}
185+
186+
func actionsPathList() ([]string, error) {
187+
actions := os.Getenv("INPUT_ACTIONS")
188+
actionsPaths := os.Getenv("INPUT_ACTIONS_PATHS")
189+
if actions != "" && actionsPaths != "" {
190+
return nil, errors.New("cannot set both INPUT_ACTIONS and INPUT_ACTIONS_PATHS")
191+
} else if actions == "" && actionsPaths == "" {
192+
// Default for actions was `.github/workflows``
193+
actions = ".github/workflows"
194+
}
195+
196+
if actions != "" {
197+
return []string{actions}, nil
198+
} else {
199+
return valToStrings(actionsPaths), nil
200+
}
201+
}

0 commit comments

Comments
 (0)