Skip to content

Commit

Permalink
Extract action path list computation to a new function to reduce cycl…
Browse files Browse the repository at this point in the history
…omatic complexity

Signed-off-by: Samuel Giddins <[email protected]>
  • Loading branch information
segiddins committed Sep 30, 2024
1 parent b5a8a46 commit 7080386
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Check failure on line 198 in main.go

View workflow job for this annotation

GitHub Actions / lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return valToStrings(actionsPaths), nil
}
}

0 comments on commit 7080386

Please sign in to comment.