Skip to content

feat: add project clone command#177

Merged
canyugs merged 2 commits intomainfrom
can/pla-578-cli-add-project-clone
Feb 25, 2026
Merged

feat: add project clone command#177
canyugs merged 2 commits intomainfrom
can/pla-578-cli-add-project-clone

Conversation

@canyugs
Copy link
Contributor

@canyugs canyugs commented Feb 24, 2026

Summary

  • Add zeabur project clone command to clone a project (with volumes, credentials, git rebinding) to a target region or dedicated server
  • Supports both interactive (project/region selector) and non-interactive modes (--id, --region, --env-id, --suspend)
  • Polls cloneProjectStatus every 3s and streams clone events until completion

Test plan

  • zeabur project clone --id <id> --region hnd1 -i=false — cloned successfully to public region
  • zeabur project clone --id <id> --region server-<id> -i=false — cloned dify to dedicated server successfully
  • zeabur project clone --help — flags displayed correctly

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • CLI command to clone projects, supporting interactive guided setup and non-interactive use
    • Choose target environment and region; real-time status polling with event streaming during cloning
    • Option to suspend the original project during cloning
    • Final success output includes quick access to the cloned project's dashboard URL

Clone a project (with volumes, credentials, git rebinding) to a target
region or dedicated server. Polls cloneProjectStatus for progress and
prints events until completion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 24, 2026 17:49
@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 457b14b and a0f3497.

📒 Files selected for processing (1)
  • internal/cmd/project/clone/clone.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/cmd/project/clone/clone.go

Walkthrough

Adds a new CLI project clone command (interactive and non-interactive), two API methods to start and poll project cloning, and model types to represent clone results and streaming events.

Changes

Cohort / File(s) Summary
CLI Command
internal/cmd/project/clone/clone.go
New command implementation with Options struct, flags, parameter validation, interactive and non-interactive flows, and polling/streaming logic for clone operations.
Command Registration
internal/cmd/project/project.go
Registers the new clone subcommand under the project command.
API Interface
pkg/api/interface.go
Adds CloneProject and CloneProjectStatus methods to the ProjectAPI interface.
API Implementation
pkg/api/project.go
Implements CloneProject (mutation) and CloneProjectStatus (query) GraphQL calls on the API client.
Data Models
pkg/model/clone.go
Adds CloneProjectResult, CloneProjectEvent, and CloneProjectStatusResult structs for clone responses and events.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant Factory
    participant API
    participant GQL

    User->>CLI: run `project clone`
    CLI->>Factory: resolve params (project, env, region)
    CLI->>API: CloneProject(projectID, envID, region, suspend)
    API->>GQL: GraphQL mutation cloneProject
    GQL-->>API: newProjectId
    API-->>CLI: CloneProjectResult
    loop poll
        CLI->>API: CloneProjectStatus(newProjectId)
        API->>GQL: GraphQL query cloneProjectStatus
        GQL-->>API: events / status / error
        API-->>CLI: CloneProjectStatusResult
        CLI->>CLI: stream events, check completion
    end
    CLI->>User: final status + dashboard URL
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add project clone command' clearly and concisely summarizes the main change—introducing a new project cloning CLI command with interactive and non-interactive modes.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch can/pla-578-cli-add-project-clone

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new zeabur project clone CLI command that triggers a backend clone operation and monitors progress until completion, enabling project duplication across regions/servers.

Changes:

  • Introduce GraphQL models for clone mutation/status events.
  • Add API client methods (CloneProject, CloneProjectStatus) and expose them via ProjectAPI.
  • Register and implement the new project clone Cobra subcommand (interactive + non-interactive flows).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/model/clone.go Adds models for clone mutation result and status/event payloads.
pkg/api/project.go Implements GraphQL mutation/query wrappers for project cloning and status polling.
pkg/api/interface.go Extends ProjectAPI with clone-related methods.
internal/cmd/project/project.go Registers the new project clone subcommand under project.
internal/cmd/project/clone/clone.go Implements the zeabur project clone command UX and polling loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +172 to +176
// Poll for status
seenEvents := 0
for {
time.Sleep(3 * time.Second)

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The status polling loop has no cancellation/timeout and sleeps before the first status query, so the command can hang indefinitely (and always waits at least 3s even if the clone finishes/fails immediately). Consider using a ticker and selecting on a context with timeout/cancel (e.g., cmd context or a --timeout flag), and query status immediately before the first wait.

Copilot uses AI. Check for mistakes.
Copy link

@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 the current code and only fix it if needed.

Inline comments:
In `@internal/cmd/project/clone/clone.go`:
- Around line 104-119: The code builds availableRegions and regionOptions from
regions then calls f.Prompter.Select and uses availableRegions[regionIndex],
which will panic if availableRegions is empty; add an explicit guard after the
loop (check len(availableRegions) == 0) and return a clear error (or handle the
no-region case) before calling f.Prompter.Select so that f.Prompter.Select and
the subsequent access to availableRegions[regionIndex].GetID() are only executed
when availableRegions contains entries.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 429f5f5 and 457b14b.

📒 Files selected for processing (5)
  • internal/cmd/project/clone/clone.go
  • internal/cmd/project/project.go
  • pkg/api/interface.go
  • pkg/api/project.go
  • pkg/model/clone.go

- Guard against empty availableRegions before prompting
- Replace sleep loop with ticker + 10-minute context timeout

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@canyugs canyugs merged commit 769d421 into main Feb 25, 2026
5 checks passed
@canyugs canyugs deleted the can/pla-578-cli-add-project-clone branch February 25, 2026 06:05
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.

2 participants