Repository navigation
fix: Handle scenario where environment name query field isn't respected - #771
Conversation
liam-mackie
left a comment
There was a problem hiding this comment.
I don't like that it's required, but the code looks good. I would prefer an additional safety check in ensuring the text passed in by the user matches either the name or the ID before returning, but otherwise LGTM!
| if len(envResponse.Items) == 1 { | ||
| return envResponse.Items[0], nil | ||
| } |
There was a problem hiding this comment.
Just in case, could we add an additional check here to ensure the ID of the space matches the ID passed in? I just don't want a case of us using the wrong environment if someone only has permissions to access one of them.
There was a problem hiding this comment.
yeah, good call. I've also changed this api call to take: 1
I'll take a look tomorrow morning. This was pretty quick and dirty |
| switch { | ||
| case len(envResponse.Items) == 0: | ||
| return nil, fmt.Errorf("environment not found") | ||
| case len(envResponse.Items) == 1 && strings.EqualFold(envResponse.Items[0].Name, nameOrID): |
There was a problem hiding this comment.
these checks are case-insensitive to match Octopus Server's case-insensitive DB query
| } | ||
|
|
||
| // double check the ID and return if true | ||
| if len(envResponse.Items) == 1 && envResponse.Items[0].ID == nameOrID { |
There was a problem hiding this comment.
this is case sensitive because ID's should be case-sensitive
## [2.31.0](v2.30.1...v2.31.0) (2026-10-19) ### Features * Obey Octopus Server rate limits ([#757](#757)) ([ca31c83](ca31c83)) ### Bug Fixes * Handle scenario where environment name query field isn't respected ([#771](#771)) ([93425bb](93425bb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: team-integrations-fnm-bot <integrationsfnmbot@octopus.com>
Older versions of Octopus Server (read before
2026.1) did not support theNameexact match parameter when querying environments.This was discovered when testing the updated TeamCity plugin using the new
release promotecommand.To fix this, when retrieving the environment, we try first by Id, then Name. If that returns multiple results, it likely means the
namequery param is not being respected and it won't be applying the filter, so will be returning more data than expected.In this case, we just do the filtering ourselves in code