Skip to content

fix(deploy): auto-pick the only project when --project is missing#22

Merged
facundofarias merged 2 commits into
mainfrom
fix/deploy-auto-pick-project
Jun 8, 2026
Merged

fix(deploy): auto-pick the only project when --project is missing#22
facundofarias merged 2 commits into
mainfrom
fix/deploy-auto-pick-project

Conversation

@facundofarias

@facundofarias facundofarias commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

dhq deploy requires --project (or DEPLOYHQ_PROJECT / .deployhq.toml), and Mixpanel shows "No project specified" as a small but steady bucket — 19 hits / 30d, 4 of them on the current v0.18.2 release, split between humans and a claude-code agent. The fix mirrors what deploy already does for servers: when there's exactly one project on the account, just use it. When there are multiple, the error now enumerates them so agents can self-correct on retry.

  • internal/commands/deploy.go — new resolveDeployProject helper: configured short-circuit, single-project auto-pick (with a Status line on stderr), zero-project hint pointing at project creation, multi-project error whose Hint lists Identifier (Name) pairs. The deploy command now resolves the project through this helper instead of RequireProject, but only when --project is missing — the configured path costs zero API calls. Long description updated so it's discoverable from --help.
  • internal/commands/deploy_test.go — five unit tests: configured short-circuit (no API hits), lone-project pick, multi-project listing, zero-project hint, and an API-error path that asserts on the first line of err.Error() to keep the "No project specified" headline continuous in the existing Mixpanel bucket.

Why scope to deploy specifically

RequireProject is called from many list/show commands; firing ListProjects from every one of them on a stale config would balloon API traffic. The data showed pain only on deploy, where the user clearly wants one project, so the auto-pick lives there and other commands keep their existing fast-fail behaviour.

Test plan

  • go test ./... — all packages green
  • golangci-lint run ./... — 0 issues
  • New tests cover configured / 1 / 0 / many / API-error branches
  • Headline-preservation assertion guards the telemetry bucket continuity

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • The deploy command now auto-determines your deploy project when none is specified and provides clear, actionable error messages for zero, multiple, or failed project lookups. Help text updated to document this behavior.
  • Tests

    • Expanded test coverage for project auto-selection, telemetry output, and error messaging across single, multiple, zero, and API-failure scenarios.

Telemetry shows "No project specified" on `dhq deploy` is a steady
small bucket (19 hits / 30d, mix of humans and a claude-code agent),
and 4/19 came from current v0.18.2. The deploy command already auto-
selects the only server on the account; extend the same symmetry to
projects, and when there are multiple, list them in the error so
agents can self-correct on retry without a separate `dhq projects list`
call.

- New resolveDeployProject helper: returns the configured project if
  set, otherwise calls ListProjects. 1 project → auto-pick with a
  Status line. 0 → tell the user to create one. >1 → UserError whose
  Hint enumerates Identifier (Name) pairs.
- "No project specified" stays as the headline string in every error
  path so the existing Mixpanel failure bucket stays continuous after
  the fix lands.
- Five unit tests cover configured short-circuit, lone-project pick,
  multi-project listing, zero-project hint, and the headline-preserved
  API-error path.
- Update the deploy command's Long description so the auto-pick is
  discoverable from `dhq deploy --help`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6e40862-9142-4d20-a4e7-285a7f1a372c

📥 Commits

Reviewing files that changed from the base of the PR and between 37559b3 and 60dcc2d.

📒 Files selected for processing (2)
  • internal/commands/deploy.go
  • internal/commands/deploy_test.go

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

This PR adds automatic project selection to the dhq deploy command. When no project is explicitly specified via --project or configuration, the new resolveDeployProject function lists available projects and auto-selects if exactly one exists, or returns actionable errors for zero/multiple projects. The change includes updated help text and comprehensive tests validating all resolution paths.

Changes

Deploy Project Auto-Resolution

Layer / File(s) Summary
Project auto-resolution logic and integration
internal/commands/deploy.go
resolveDeployProject auto-determines the project by listing and selecting the only one, or returning errors with hints for zero/multiple projects or API failures. Help text documents the behavior. Command initialization deferred project resolution until after flag validation, replacing early cliCtx.RequireProject() with the new helper.
Tests and test helpers for project resolution
internal/commands/deploy_test.go
Test imports added for output buffering. testEnvelope helper constructed test envelopes with buffered stderr. New test suite covers configured project short-circuit, single-project auto-pick with telemetry, multi/zero-project errors with headline/hints, and API error headline preservation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely summarizes the main change: auto-picking the only project when --project is missing, which is the core feature added in this PR.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/deploy-auto-pick-project

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

…project

# Conflicts:
#	internal/commands/deploy_test.go
@facundofarias facundofarias merged commit f312a28 into main Jun 8, 2026
2 of 3 checks passed
@facundofarias facundofarias deleted the fix/deploy-auto-pick-project branch June 8, 2026 09:16
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