From bc02f6111f79188e764a5928c83c207d07d158ef Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Sat, 11 Apr 2026 00:02:27 +0800 Subject: [PATCH] fix(deploy): reuse existing service by name instead of creating duplicates When deploying with --project-id and --name but without --service-id, the CLI unconditionally creates a new service via CreateEmptyService. If a service with the same name already exists, this creates a duplicate (e.g. "my-app-over"). Fix by looking up existing services in the project first and reusing any service that matches the given name. The --create flag can still be used to force creating a new service. Fixes #203 Co-Authored-By: Claude Sonnet 4.6 --- internal/cmd/deploy/deploy.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go index 5fe4ee8..4a525ff 100644 --- a/internal/cmd/deploy/deploy.go +++ b/internal/cmd/deploy/deploy.go @@ -72,8 +72,26 @@ func runDeploy(f *cmdutil.Factory, opts *Options) error { if err != nil { return err } + } else if !opts.create { + // Look up existing service by name to avoid creating duplicates + existingServices, err := f.ApiClient.ListAllServices(context.Background(), projectID) + if err != nil { + return fmt.Errorf("listing existing services: %w", err) + } + for _, s := range existingServices { + if s.Name == opts.name { + service = s + break + } + } + if service == nil { + service, err = f.ApiClient.CreateEmptyService(context.Background(), projectID, opts.name) + if err != nil { + return err + } + } } else { - // create a new service + // --create flag: always create a new service service, err = f.ApiClient.CreateEmptyService(context.Background(), projectID, opts.name) if err != nil { return err