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

Function ResolveEnvironmentNames

pkg/cmd/account/helper/helper.go:13–36  ·  view source on GitHub ↗

ResolveEnvironmentNames takes in an array of names and trys to find an exact match. If a match is found it will return its corresponding ID. If no match is found it will return the name as is, in assumption it is an ID.

(envs []string, octopus *client.Client)

Source from the content-addressed store, hash-verified

11// If a match is found it will return its corresponding ID. If no match is found
12// it will return the name as is, in assumption it is an ID.
13func ResolveEnvironmentNames(envs []string, octopus *client.Client) ([]string, error) {
14 envIds := make([]string, 0, len(envs))
15loop:
16 for _, envName := range envs {
17 matches, err := octopus.Environments.Get(environments.EnvironmentsQuery{
18 Name: envName,
19 })
20 if err != nil {
21 return nil, err
22 }
23 allMatches, err := matches.GetAllPages(octopus.Environments.GetClient())
24 if err != nil {
25 return nil, err
26 }
27 for _, match := range allMatches {
28 if strings.EqualFold(envName, match.Name) {
29 envIds = append(envIds, match.ID)
30 continue loop
31 }
32 }
33 envIds = append(envIds, envName)
34 }
35 return envIds, nil
36}

Callers 8

NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdCreateFunction · 0.92

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected