Repository navigation
feat: add task list command (from #742) - #744
NickJosevski wants to merge 6 commits into
Conversation
Adds 'octopus task list' to list server tasks, filtered by project, environment (including ephemeral environments) and state. Output supports table, json and basic formats, where basic prints task IDs so the result can be piped into 'octopus task wait'. Previously tasks could only be waited on by ID, so automation had to call the REST API to discover in-flight deployments and runbook runs.
| environment, err := selectors.FindEnvironment(octopus, nameOrID) | ||
| if err == nil { | ||
| return environment.GetID(), nil | ||
| } | ||
|
|
||
| ephemeralEnvironment, ephemeralErr := util.GetByName(octopus, nameOrID, octopus.GetSpaceID()) | ||
| if ephemeralErr == nil { | ||
| return ephemeralEnvironment.ID, nil | ||
| } | ||
|
|
||
| return "", fmt.Errorf("no environment or ephemeral environment found with name of %s", nameOrID) |
There was a problem hiding this comment.
resolveEnvironmentID throws away both lookup errors. It reports no environment or ephemeral environment found whether the lookups returned not-found or something else.
- Misleading message: If
FindEnvironmentfails for any other reason (auth/permission error, network failure, server error), the code falls through to the ephemeral lookup. If that also fails, the user sees a "not found" message even though the environment may exist. - Hidden cause: The real failure is hidden, which makes CI failures hard to diagnose.
Suggested fix:
- Only fall back to the ephemeral lookup when the first error is a not-found condition.
- Otherwise return the original error, wrapping
err/ephemeralErrso the underlying cause is preserved.
There was a problem hiding this comment.
Thanks, agreed. Fixed on the #742 branch (justin-newman:feat/task-list) in d345e81, with a follow-up test fix in 1fc708e.
resolveEnvironmentID now looks up regular environments directly and only falls back to ephemeral environments when that lookup succeeds with no match. A failed lookup is returned wrapped with %w (failed to look up environment '<name>' or failed to look up ephemeral environment '<name>'), so the underlying cause is preserved. The generic "no environment or ephemeral environment found" message is now only used when both lookups succeed and neither matches. I did not use errors.Is for the not-found case because FindEnvironment and the ephemeral GetByName report not-found as plain fmt.Errorf strings.
Both failure paths have tests, and the unit suite passes on my fork: https://github.com/justin-newman/octopus-cli/actions/runs/37982658151
I can't push to justin-newman-742, so this needs pulling into #744 or re-creating from #742.
From: #742
Adds 'octopus task list' to list server tasks, filtered by project,
environment (including ephemeral environments) and state. Output
supports table, json and basic formats, where basic prints task IDs
so the result can be piped into 'octopus task wait'.
Previously tasks could only be waited on by ID, so automation had to
call the REST API to discover in-flight deployments and runbook runs.