Skip to content

chore: get deployment by name#73

Merged
adityachoudhari26 merged 1 commit intomainfrom
get-deployment-name
May 7, 2026
Merged

chore: get deployment by name#73
adityachoudhari26 merged 1 commit intomainfrom
get-deployment-name

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented May 7, 2026

Summary by CodeRabbit

  • New Features

    • Added CLI command to retrieve deployments by name.
    • Added ability to manage deployment version dependencies (list, create/update, delete).
    • Added retrieval by name for deployments and environments.
    • Introduced enhanced query parameters for improved filtering capabilities.
  • Chores

    • Updated API schema models and types to reflect latest specifications.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This 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 ctrlc get deployment command leverages these capabilities.

Changes

Deployment Lookup & Dependency Features

Layer / File(s) Summary
API Schema & Models
internal/api/client.gen.go
Adds DeploymentPlanTargetResultStatus constants, DeploymentVersionDependency and PlanValidationOpaRule types, updates CreateDeploymentVersionRequest with Dependencies map, refactors DeploymentPlanTarget/Result fields to use required instead of optional types, and updates EnvironmentProgressionRule with soak-time and verification fields.
API Client Methods
internal/api/client.gen.go
Adds GetDeploymentByName and GetEnvironmentByName methods, dependency CRUD methods (ListDeploymentVersionDependencies, RequestDeploymentVersionDependencyUpsert, RequestDeploymentVersionDependencyDeletion), and CEL query parameter support to ListDeployments and ListDeploymentVersions endpoints.
Deployment CLI Command
cmd/ctrlc/root/api/get/deployment/deployment.go
Implements NewDeploymentCmd Cobra command with required --name and --workspace flags that resolves workspace ID, fetches deployment by name via the API client, and outputs the response.
CLI Integration
cmd/ctrlc/root/api/get/get.go
Imports the deployment package and registers deployment.NewDeploymentCmd() as a subcommand of the get command.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ctrlplanedev/cli#54: Modifies internal/api/client.gen.go and introduces/alters deployment-related API methods used by the new by-name deployment getter.

Suggested reviewers

  • jsbroks

Poem

🐰 A rabbit hops through deployments with glee,
Finding them by name—a query spree!
Dependencies tracked, plans all pristine,
CEL filters clean, OPA rules keen!
hop hop 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new subcommand to fetch deployments by name, which is evident from the NewDeploymentCmd implementation and integration.
Docstring Coverage ✅ Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch get-deployment-name

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd6033 and 375c01f.

📒 Files selected for processing (3)
  • cmd/ctrlc/root/api/get/deployment/deployment.go
  • cmd/ctrlc/root/api/get/get.go
  • internal/api/client.gen.go

Comment on lines +39 to +41
cmd.MarkFlagRequired("name")

cmd.MarkFlagRequired("workspace")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 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=go

Repository: ctrlplanedev/cli

Length of output: 4973


🏁 Script executed:

cat -n cmd/ctrlc/root/api/get/deployment/deployment.go

Repository: 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 -50

Repository: ctrlplanedev/cli

Length of output: 626


🏁 Script executed:

# Check the root/api command structure
cat -n cmd/ctrlc/root/api/api.go | head -100

Repository: ctrlplanedev/cli

Length of output: 2047


🏁 Script executed:

# Check root command for persistent flags
cat -n cmd/ctrlc/root/root.go | head -150

Repository: ctrlplanedev/cli

Length of output: 2494


🏁 Script executed:

# Check how other get commands handle workspace
cat -n cmd/ctrlc/root/api/get/release/release.go

Repository: ctrlplanedev/cli

Length of output: 1475


🏁 Script executed:

# Check get/resources
cat -n cmd/ctrlc/root/api/get/resources/resources.go

Repository: 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=go

Repository: 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
done

Repository: 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.

@adityachoudhari26 adityachoudhari26 merged commit 4fd3bc6 into main May 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant