From 433940cd48fa4d0e4a9c6632032ef33731633366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20Houn?= Date: Tue, 27 Feb 2024 19:52:39 +0000 Subject: [PATCH] fix: reorganise commands/variable/update like commands/variable/set --- commands/variable/update/update.go | 52 +++++++++++++----------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/commands/variable/update/update.go b/commands/variable/update/update.go index bc6c1f14..cffd9ff9 100644 --- a/commands/variable/update/update.go +++ b/commands/variable/update/update.go @@ -108,35 +108,7 @@ func updateRun(opts *UpdateOpts) error { return err } - baseRepo, err := opts.BaseRepo() - if err != nil { - return err - } - - if opts.Group == "" { - // update project-level variable - updateProjectVarOpts := &gitlab.UpdateProjectVariableOptions{ - Value: gitlab.String(opts.Value), - VariableType: gitlab.VariableType(gitlab.VariableTypeValue(opts.Type)), - Masked: gitlab.Bool(opts.Masked), - Protected: gitlab.Bool(opts.Protected), - Raw: gitlab.Bool(opts.Raw), - EnvironmentScope: gitlab.String(opts.Scope), - } - - _, err = api.UpdateProjectVariable(httpClient, baseRepo.FullName(), opts.Key, updateProjectVarOpts) - if err != nil { - return err - } - - fmt.Fprintf(opts.IO.StdOut, - "%s Updated variable %s for project %s with scope %s\n", - c.GreenCheck(), - opts.Key, - baseRepo.FullName(), - opts.Scope) - - } else { + if opts.Group != "" { // update group-level variable updateGroupVarOpts := &gitlab.UpdateGroupVariableOptions{ Value: gitlab.String(opts.Value), @@ -153,7 +125,29 @@ func updateRun(opts *UpdateOpts) error { } fmt.Fprintf(opts.IO.StdOut, "%s Updated variable %s for group %s\n", c.GreenCheck(), opts.Key, opts.Group) + return nil } + // update project-level variable + baseRepo, err := opts.BaseRepo() + if err != nil { + return err + } + + updateProjectVarOpts := &gitlab.UpdateProjectVariableOptions{ + Value: gitlab.String(opts.Value), + VariableType: gitlab.VariableType(gitlab.VariableTypeValue(opts.Type)), + Masked: gitlab.Bool(opts.Masked), + Protected: gitlab.Bool(opts.Protected), + Raw: gitlab.Bool(opts.Raw), + EnvironmentScope: gitlab.String(opts.Scope), + } + + _, err = api.UpdateProjectVariable(httpClient, baseRepo.FullName(), opts.Key, updateProjectVarOpts) + if err != nil { + return err + } + + fmt.Fprintf(opts.IO.StdOut, "%s Updated variable %s for project %s with scope %s\n", c.GreenCheck(), opts.Key, baseRepo.FullName(), opts.Scope) return nil }