chore: get deployment by name#73
Conversation
📝 WalkthroughWalkthroughThis PR adds deployment query and dependency management capabilities to the API client, then exposes deployment lookup via a new CLI subcommand. The generated client adds methods for fetching deployments by name, managing version dependencies, filtering with CEL expressions, and validates deployments using OPA rules. The new ChangesDeployment Lookup & Dependency Features
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/ctrlc/root/api/get/deployment/deployment.go`:
- Around line 39-41: The command calls cmd.MarkFlagRequired("workspace") for a
flag that isn't declared, so add explicit runtime validation inside the
command's RunE handler (the RunE function for this get deployment command) to
fetch the workspace via viper.GetString("workspace") and return an error like
"workspace is required" if it's empty; alternatively, if workspace should be a
user flag, declare it on the command (e.g., cmd.Flags().String("workspace", "",
"...")) before calling cmd.MarkFlagRequired("workspace"). Also remove any
ineffective MarkFlagRequired("workspace") calls if you choose the runtime
validation route.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cd67ad93-0a28-466f-a1c3-681e9c434cbe
📒 Files selected for processing (3)
cmd/ctrlc/root/api/get/deployment/deployment.gocmd/ctrlc/root/api/get/get.gointernal/api/client.gen.go
| cmd.MarkFlagRequired("name") | ||
|
|
||
| cmd.MarkFlagRequired("workspace") |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify how `workspace` is declared and whether this command can mark it required.
# Expected:
# - If workspace is only persistent on a parent command, MarkFlagRequired here won't enforce it.
# - Identify other command patterns used in this repo for inherited required flags.
rg -n -C3 'StringVarP?\([^)]*"workspace"' --type=go
rg -n -C3 'PersistentFlags\(\)\.StringVarP?\([^)]*"workspace"' --type=go
rg -n -C3 'MarkFlagRequired\("workspace"\)|MarkPersistentFlagRequired\("workspace"\)' --type=goRepository: ctrlplanedev/cli
Length of output: 4973
🏁 Script executed:
cat -n cmd/ctrlc/root/api/get/deployment/deployment.goRepository: ctrlplanedev/cli
Length of output: 1498
🏁 Script executed:
# Check parent commands to see if workspace is a persistent flag
rg -n "PersistentFlags" cmd/ctrlc/root/api/get/deployment/ --type=go -A5
rg -n "PersistentFlags" cmd/ctrlc/root/api/ --type=go -A5 | head -50Repository: ctrlplanedev/cli
Length of output: 626
🏁 Script executed:
# Check the root/api command structure
cat -n cmd/ctrlc/root/api/api.go | head -100Repository: ctrlplanedev/cli
Length of output: 2047
🏁 Script executed:
# Check root command for persistent flags
cat -n cmd/ctrlc/root/root.go | head -150Repository: ctrlplanedev/cli
Length of output: 2494
🏁 Script executed:
# Check how other get commands handle workspace
cat -n cmd/ctrlc/root/api/get/release/release.goRepository: ctrlplanedev/cli
Length of output: 1475
🏁 Script executed:
# Check get/resources
cat -n cmd/ctrlc/root/api/get/resources/resources.goRepository: ctrlplanedev/cli
Length of output: 2003
🏁 Script executed:
# Check how many commands have this workspace MarkFlagRequired pattern
rg -l 'MarkFlagRequired\("workspace"\)' cmd/ctrlc/root/ --type=goRepository: ctrlplanedev/cli
Length of output: 228
🏁 Script executed:
# For each file with this pattern, check if workspace is declared as a local flag
for file in $(rg -l 'MarkFlagRequired\("workspace"\)' cmd/ctrlc/root/ --type=go); do
echo "=== $file ==="
if grep -q 'StringVarP.*"workspace"' "$file"; then
echo "✓ workspace IS declared as local flag"
else
echo "✗ workspace NOT declared as local flag"
fi
doneRepository: ctrlplanedev/cli
Length of output: 415
Required-flag enforcement for workspace is not working and affects 3 commands.
Line 41 calls MarkFlagRequired("workspace") on a flag that is not declared in this command. Cobra silently ignores this call, so no validation occurs. The workspace value comes only from viper.GetString() at runtime (line 21); if empty, it will be passed to client.GetWorkspaceID() and likely cause runtime errors.
This same issue affects cmd/ctrlc/root/api/get/release/release.go and cmd/ctrlc/root/api/get/resources/resources.go — both call MarkFlagRequired("workspace") without declaring the flag locally. Only cmd/ctrlc/root/agent/run/run.go correctly declares the flag before marking it required.
Add runtime validation for workspace in the RunE function to ensure early failure with a clear error message:
Suggested fix
RunE: func(cmd *cobra.Command, args []string) error {
apiURL := viper.GetString("url")
apiKey := viper.GetString("api-key")
workspace := viper.GetString("workspace")
+ if workspace == "" {
+ return fmt.Errorf("workspace is required")
+ }Remove the ineffective MarkFlagRequired() calls on line 39 and 41, or declare workspace as an actual flag if it should be user-provided.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/ctrlc/root/api/get/deployment/deployment.go` around lines 39 - 41, The
command calls cmd.MarkFlagRequired("workspace") for a flag that isn't declared,
so add explicit runtime validation inside the command's RunE handler (the RunE
function for this get deployment command) to fetch the workspace via
viper.GetString("workspace") and return an error like "workspace is required" if
it's empty; alternatively, if workspace should be a user flag, declare it on the
command (e.g., cmd.Flags().String("workspace", "", "...")) before calling
cmd.MarkFlagRequired("workspace"). Also remove any ineffective
MarkFlagRequired("workspace") calls if you choose the runtime validation route.
Summary by CodeRabbit
New Features
Chores