Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add env update-components not filtering by component name the ma… #53

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions cmd/environment/action/update.components.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"bunnyshell.com/cli/pkg/util"
"bunnyshell.com/sdk"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/slice"
)

type EditComponentsSource struct {
Expand Down Expand Up @@ -70,10 +71,12 @@ func init() {
return nil
}

matchedComponentNames := componentToNamesList(matched)

printLogs := settings.IsStylish()

if printLogs {
cmd.Printf(`Updating components "%s"%s`, componentToString(matched), "\n\n")
cmd.Printf(`Updating components "%s"%s`, strings.Join(matchedComponentNames, ", "), "\n\n")
}

model, err := environment.EditComponents(editOptions)
Expand All @@ -86,7 +89,7 @@ func init() {
}

if !editOptions.WithDeploy {
return showGitInfo(cmd, model.GetId())
return showUpdateGitInfo(cmd, model.GetId(), matchedComponentNames)
}

deployOptions := &editOptions.DeployOptions
Expand All @@ -96,7 +99,7 @@ func init() {
return err
}

return showGitInfo(cmd, model.GetId())
return showUpdateGitInfo(cmd, model.GetId(), matchedComponentNames)
},
}

Expand Down Expand Up @@ -130,10 +133,14 @@ func findMatchedComponents(editOptions *environment.EditComponentOptions) ([]sdk
aggOptions.GitBranch = editOptions.SourceBranch
}

if editOptions.Component != "" {
aggOptions.Name = editOptions.Component
}

return git.Aggregate(aggOptions)
}

func showGitInfo(cmd *cobra.Command, environment string) error {
func showUpdateGitInfo(cmd *cobra.Command, environment string, componentNames []string) error {
listOptions := git.NewAggregateOptions()
listOptions.Environment = environment

Expand All @@ -142,17 +149,24 @@ func showGitInfo(cmd *cobra.Command, environment string) error {
return err
}

return lib.FormatCommandData(cmd, agg)
filtered := []sdk.ComponentGitCollection{}
for _, element := range agg {
if slice.ContainsString(componentNames, element.GetName(), nil) {
filtered = append(filtered, element)
}
}

return lib.FormatCommandData(cmd, filtered)
}

func componentToString(matched []sdk.ComponentGitCollection) string {
func componentToNamesList(matched []sdk.ComponentGitCollection) []string {
components := []string{}

for _, item := range matched {
components = append(components, item.GetName())
}

return strings.Join(components, ", ")
return components
}

func fillWithGitSpec(editSource *EditComponentsSource, editOptions *environment.EditComponentOptions) error {
Expand Down
Loading