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)
| 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. |
| 13 | func ResolveEnvironmentNames(envs []string, octopus *client.Client) ([]string, error) { |
| 14 | envIds := make([]string, 0, len(envs)) |
| 15 | loop: |
| 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 | } |
no test coverage detected