MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / UpdateProjectVariableValue

Function UpdateProjectVariableValue

pkg/cmd/tenant/variables/update/update.go:685–806  ·  view source on GitHub ↗
(opts *UpdateOptions, vars []variables.TenantProjectVariable, missingVars []variables.TenantProjectVariable, environmentMap map[string]string)

Source from the content-addressed store, hash-verified

683}
684
685func UpdateProjectVariableValue(opts *UpdateOptions, vars []variables.TenantProjectVariable, missingVars []variables.TenantProjectVariable, environmentMap map[string]string) (bool, []variables.TenantProjectVariablePayload, error) {
686 var environmentIds []string
687 for id, environment := range environmentMap {
688 for _, optEnvironment := range opts.Environments.Value {
689 if strings.EqualFold(environment, optEnvironment) || strings.EqualFold(id, optEnvironment) {
690 environmentIds = append(environmentIds, id)
691 }
692 }
693 }
694
695 var variablesWithMatchingProject []variables.TenantProjectVariable
696 for _, v := range vars {
697 if strings.EqualFold(v.ProjectName, opts.Project.Value) {
698 variablesWithMatchingProject = append(variablesWithMatchingProject, v)
699 }
700 }
701
702 var variablesWithMatchingTemplate []variables.TenantProjectVariable
703 for _, v := range variablesWithMatchingProject {
704 if strings.EqualFold(v.Template.Name, opts.Name.Value) {
705 variablesWithMatchingTemplate = append(variablesWithMatchingTemplate, v)
706 }
707 }
708
709 var variablesWithMatchingScope []variables.TenantProjectVariable
710 for _, v := range variablesWithMatchingTemplate {
711 if util.SliceEquals(v.Scope.EnvironmentIds, environmentIds) {
712 variablesWithMatchingScope = append(variablesWithMatchingScope, v)
713 }
714 }
715
716 var matchingMissingVariables []variables.TenantProjectVariable
717 if len(variablesWithMatchingScope) == 0 {
718 if len(missingVars) > 0 {
719 var missingVariablesWithMatchingTemplate []variables.TenantProjectVariable
720 for _, v := range missingVars {
721 if strings.EqualFold(v.ProjectName, opts.Project.Value) && strings.EqualFold(v.Template.Name, opts.Name.Value) {
722 missingVariablesWithMatchingTemplate = append(missingVariablesWithMatchingTemplate, v)
723 }
724 }
725
726 for _, v := range missingVariablesWithMatchingTemplate {
727 if util.SliceContainsSlice(v.Scope.EnvironmentIds, environmentIds) {
728 variablesWithMatchingTemplate = append(variablesWithMatchingTemplate, missingVariablesWithMatchingTemplate[0])
729 }
730 }
731 for _, v := range missingVariablesWithMatchingTemplate {
732 if util.SliceContainsSlice(v.Scope.EnvironmentIds, environmentIds) {
733 variablesWithMatchingTemplate = append(variablesWithMatchingTemplate, missingVariablesWithMatchingTemplate[0])
734 matchingMissingVariables = append(matchingMissingVariables, missingVariablesWithMatchingTemplate[0])
735 }
736 }
737
738 }
739
740 if len(variablesWithMatchingTemplate) > 0 && len(matchingMissingVariables) == 0 {
741 if len(opts.Environments.Value) == 0 {
742 matchingMissingVariables = append(matchingMissingVariables, variablesWithMatchingTemplate[0])

Calls 4

SliceEqualsFunction · 0.92
SliceContainsSliceFunction · 0.92
convertValueFunction · 0.85