From 68e901c7df824156c104e2e0926fccd11facc41e Mon Sep 17 00:00:00 2001 From: Raymond Hou Date: Fri, 27 Mar 2026 08:14:53 +0800 Subject: [PATCH] fix: reuse existing service by name instead of creating duplicates (#203) When deploying with `--project-id` and `--name` but without `--service-id`, the CLI now checks if a service with the same name already exists in the project. If found, it reuses that service instead of creating a duplicate with a suffixed name (e.g. "my-app-over"). Co-Authored-By: Claude Opus 4.6 (1M context) --- internal/cmd/deploy/deploy.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go index 5fe4ee8..ba8b1f2 100644 --- a/internal/cmd/deploy/deploy.go +++ b/internal/cmd/deploy/deploy.go @@ -73,10 +73,27 @@ func runDeploy(f *cmdutil.Factory, opts *Options) error { return err } } else { - // create a new service - service, err = f.ApiClient.CreateEmptyService(context.Background(), projectID, opts.name) - if err != nil { - return err + // check if a service with the same name already exists + if opts.name != "" { + existingServices, err := f.ApiClient.ListAllServices(context.Background(), projectID) + if err != nil { + return fmt.Errorf("listing services: %w", err) + } + for _, s := range existingServices { + if s.Name == opts.name { + service = s + f.Log.Infof("Found existing service '%s', redeploying...", opts.name) + break + } + } + } + + // create a new service if no existing one was found + if service == nil { + service, err = f.ApiClient.CreateEmptyService(context.Background(), projectID, opts.name) + if err != nil { + return err + } } }