Skip to content

Commit

Permalink
refactor: Use new iterator in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
Laubi committed Jan 23, 2025
1 parent bfa02cb commit 672307f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
13 changes: 7 additions & 6 deletions cmd/monaco/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,29 @@ func validateProjectsWithEnvironments(projects []project.Project, envs manifest.
}

func collectOpenPipelineCoordinatesByKind(cfgPerType v2.ConfigsPerType, dest KindCoordinates) {
cfgPerType.ForEveryConfigDo(func(cfg config.Config) {
for cfg := range cfgPerType.AllConfigs {
if cfg.Skip {
return
continue
}

if openPipelineType, ok := cfg.Type.(config.OpenPipelineType); ok {
dest[openPipelineType.Kind] = append(dest[openPipelineType.Kind], cfg.Coordinate)
}
})
}
}

func collectPlatformCoordinates(cfgPerType v2.ConfigsPerType) []coordinate.Coordinate {
plaformCoordinates := []coordinate.Coordinate{}
cfgPerType.ForEveryConfigDo(func(cfg config.Config) {

for cfg := range cfgPerType.AllConfigs {
if cfg.Skip {
return
continue
}

if configRequiresPlatform(cfg) {
plaformCoordinates = append(plaformCoordinates, cfg.Coordinate)
}
})
}
return plaformCoordinates
}

Expand Down
24 changes: 7 additions & 17 deletions pkg/project/v2/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,24 @@ func (p Project) String() string {

// ForEveryConfigDo executes the given ActionOverConfig actions for each configuration defined in the project for each environment
// Actions can not modify the configs inside the Project.
func (p Project) ForEveryConfigDo(actions ...ActionOverConfig) {
p.forEveryConfigDo("", actions)
func (p Project) ForEveryConfigDo(action ActionOverConfig) {
p.forEveryConfigDo("", action)
}

// ForEveryConfigInEnvironmentDo executes the given ActionOverConfig actions for each configuration defined in the project for a given environment.
// It behaves like ForEveryConfigDo just limited to a single environment.
// Actions can not modify the configs inside the Project.
func (p Project) ForEveryConfigInEnvironmentDo(environment string, actions ...ActionOverConfig) {
p.forEveryConfigDo(environment, actions)
func (p Project) ForEveryConfigInEnvironmentDo(environment string, action ActionOverConfig) {
p.forEveryConfigDo(environment, action)
}

// forEveryConfigDo applies the given action to every configuration, either for a single environment if requested,
// or for all environments if the environemnt parameter is empty.
func (p Project) forEveryConfigDo(environment string, actions []ActionOverConfig) {
func (p Project) forEveryConfigDo(environment string, action ActionOverConfig) {
for env, cpt := range p.Configs {
if environment == "" || environment == env {
cpt.ForEveryConfigDo(actions...)
}
}
}

// ForEveryConfigDo executes the given ActionOverConfig actions for each configuration defined in the ConfigsPerType.
// Actions can not modify the configs inside the ConfigsPerType.
func (cpt ConfigsPerType) ForEveryConfigDo(actions ...ActionOverConfig) {
for _, cs := range cpt {
for _, c := range cs {
for _, f := range actions {
f(c)
for c := range cpt.AllConfigs {
action(c)
}
}
}
Expand Down

0 comments on commit 672307f

Please sign in to comment.