Skip to content

Commit 458fbca

Browse files
Cr 7637 add default git intg (#161)
1 parent 876206c commit 458fbca

24 files changed

+251
-454
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* roi.kramer@codefresh.io

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.155
1+
VERSION=v0.0.156
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ func presetRequiredFlags(cmd *cobra.Command) {
7171
cmd.Flags().SortFlags = false
7272
}
7373

74-
func IsValid(s string) (bool, error) {
74+
func IsValidName(s string) (bool, error) {
7575
return regexp.MatchString(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`, s)
7676
}
7777

78-
func askUserIfToInstallCodefreshSamples(cmd *cobra.Command, sampleInstall *bool) error {
78+
func askUserIfToInstallDemoResources(cmd *cobra.Command, sampleInstall *bool) error {
7979
if !store.Get().Silent && !cmd.Flags().Changed("sample-install") {
8080
templates := &promptui.SelectTemplates{
8181
Selected: "{{ . | yellow }} ",
8282
}
8383

84-
labelStr := fmt.Sprintf("%vInstall codefresh samples?%v", CYAN, COLOR_RESET)
84+
labelStr := fmt.Sprintf("%vInstall Codefresh demo resources?%v", CYAN, COLOR_RESET)
8585

8686
prompt := promptui.Select{
8787
Label: labelStr,
@@ -211,6 +211,7 @@ func ensureGitToken(cmd *cobra.Command, cloneOpts *git.CloneOptions) error {
211211
func getGitTokenFromUserInput(cmd *cobra.Command) error {
212212
gitTokenPrompt := promptui.Prompt{
213213
Label: "Git provider api token",
214+
Mask: '*',
214215
}
215216
gitTokenInput, err := gitTokenPrompt.Run()
216217
if err != nil {
@@ -315,21 +316,23 @@ func getKubeContextNameFromUserSelect(cmd *cobra.Command, kubeContextName *strin
315316
}
316317

317318
func getIngressHostFromUserInput(cmd *cobra.Command, ingressHost *string) error {
318-
if store.Get().Silent {
319+
if ingressHost != nil && *ingressHost != "" {
319320
return nil
320321
}
321322

322-
if ingressHost != nil && *ingressHost != "" {
323-
return nil
323+
if store.Get().Silent {
324+
return fmt.Errorf("missing ingress host")
324325
}
325326

326327
ingressHostPrompt := promptui.Prompt{
327-
Label: "Ingress host (leave blank to skip)",
328+
Label: "Ingress host (required)",
328329
}
329330

330331
ingressHostInput, err := ingressHostPrompt.Run()
331332
if err != nil {
332333
return fmt.Errorf("Prompt error: %w", err)
334+
} else if ingressHostInput == "" {
335+
return fmt.Errorf("missing ingress host")
333336
}
334337

335338
die(cmd.Flags().Set("ingress-host", ingressHostInput))
@@ -338,7 +341,7 @@ func getIngressHostFromUserInput(cmd *cobra.Command, ingressHost *string) error
338341
return nil
339342
}
340343

341-
func verifyLatestVersion(ctx context.Context) error {
344+
func verifyCLILatestVersion(ctx context.Context) error {
342345
latestVersionString, err := cfConfig.NewClient().V2().CliReleases().GetLatest(ctx)
343346
if err != nil {
344347
return fmt.Errorf("failed getting latest cli release: %w", err)

cmd/commands/component.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewComponentListCommand() *cobra.Command {
5959
RunE: func(cmd *cobra.Command, args []string) error {
6060
ctx := cmd.Context()
6161

62-
if err := verifyLatestVersion(ctx); err != nil {
62+
if err := verifyCLILatestVersion(ctx); err != nil {
6363
return err
6464
}
6565

cmd/commands/git-source.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
141141
return err
142142
}
143143

144-
isValid, err := IsValid(args[1])
144+
isValid, err := IsValidName(args[1])
145145
if err != nil {
146146
log.G(ctx).Fatal("failed to check the validity of the git-source name")
147147
}
@@ -166,7 +166,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
166166
RunE: func(cmd *cobra.Command, args []string) error {
167167
ctx := cmd.Context()
168168

169-
if err := verifyLatestVersion(ctx); err != nil {
169+
if err := verifyCLILatestVersion(ctx); err != nil {
170170
return err
171171
}
172172

@@ -388,7 +388,7 @@ func NewGitSourceListCommand() *cobra.Command {
388388
RunE: func(cmd *cobra.Command, args []string) error {
389389
ctx := cmd.Context()
390390

391-
if err := verifyLatestVersion(ctx); err != nil {
391+
if err := verifyCLILatestVersion(ctx); err != nil {
392392
return err
393393
}
394394

@@ -489,7 +489,7 @@ func NewGitSourceDeleteCommand() *cobra.Command {
489489
RunE: func(cmd *cobra.Command, args []string) error {
490490
ctx := cmd.Context()
491491

492-
if err := verifyLatestVersion(ctx); err != nil {
492+
if err := verifyCLILatestVersion(ctx); err != nil {
493493
return err
494494
}
495495

@@ -564,7 +564,7 @@ func NewGitSourceEditCommand() *cobra.Command {
564564
RunE: func(cmd *cobra.Command, args []string) error {
565565
ctx := cmd.Context()
566566

567-
if err := verifyLatestVersion(ctx); err != nil {
567+
if err := verifyCLILatestVersion(ctx); err != nil {
568568
return err
569569
}
570570

cmd/commands/integrations.go

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ type (
3939
}
4040
)
4141

42+
var gitProvidersByName = map[string]model.GitProviders{
43+
"github": model.GitProvidersGithub,
44+
"gitlab": model.GitProvidersGitlab,
45+
}
46+
4247
func NewIntegrationCommand() *cobra.Command {
4348
var (
4449
runtime string
@@ -60,6 +65,8 @@ func NewIntegrationCommand() *cobra.Command {
6065

6166
cmd.AddCommand(NewGitIntegrationCommand(&client))
6267

68+
cmd.Hidden = true // hide this command for now
69+
6370
return cmd
6471
}
6572

@@ -142,24 +149,25 @@ func RunGitIntegrationListCommand(ctx context.Context, client sdk.AppProxyAPI, f
142149

143150
func NewGitIntegrationGetCommand(client *sdk.AppProxyAPI) *cobra.Command {
144151
var (
145-
format string
152+
format string
153+
integration *string
146154
)
147155

148156
allowedFormats := []string{"yaml", "yml", "json"}
149157

150158
cmd := &cobra.Command{
151-
Use: "get NAME",
159+
Use: "get [NAME]",
152160
Short: "Retrieve a git integration",
153161
RunE: func(cmd *cobra.Command, args []string) error {
154-
if len(args) < 1 {
155-
return fmt.Errorf("missing integration name")
162+
if len(args) > 0 {
163+
integration = &args[0]
156164
}
157165

158166
if err := verifyOutputFormat(format, allowedFormats...); err != nil {
159167
return err
160168
}
161169

162-
return RunGitIntegrationGetCommand(cmd.Context(), *client, args[0], format)
170+
return RunGitIntegrationGetCommand(cmd.Context(), *client, integration, format)
163171
},
164172
}
165173

@@ -168,7 +176,7 @@ func NewGitIntegrationGetCommand(client *sdk.AppProxyAPI) *cobra.Command {
168176
return cmd
169177
}
170178

171-
func RunGitIntegrationGetCommand(ctx context.Context, client sdk.AppProxyAPI, name, format string) error {
179+
func RunGitIntegrationGetCommand(ctx context.Context, client sdk.AppProxyAPI, name *string, format string) error {
172180
gi, err := client.GitIntegrations().Get(ctx, name)
173181
if err != nil {
174182
return fmt.Errorf("failed to get git integration: %w", err)
@@ -184,26 +192,19 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
184192
accountAdminsOnly bool
185193
)
186194

187-
providers := map[string]model.GitProviders{
188-
"github": model.GitProvidersGithub,
189-
"gitlab": model.GitProvidersGitlab,
190-
}
191-
192195
cmd := &cobra.Command{
193-
Use: "add NAME",
196+
Use: "add [NAME]",
194197
Short: "Add a new git integration",
195198
RunE: func(cmd *cobra.Command, args []string) error {
196-
if len(args) < 1 {
197-
return fmt.Errorf("missing integration name")
198-
}
199+
var err error
199200

200-
opts.Name = args[0]
201+
if len(args) > 0 {
202+
opts.Name = &args[0]
203+
}
201204

202-
p, ok := providers[provider]
203-
if !ok {
204-
return fmt.Errorf("provider '%s' is not a valid provider name", provider)
205+
if opts.Provider, err = parseGitProvider(provider); err != nil {
206+
return err
205207
}
206-
opts.Provider = p
207208

208209
opts.SharingPolicy = model.SharingPolicyAllUsersInAccount
209210
if accountAdminsOnly {
@@ -242,15 +243,13 @@ func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
242243
)
243244

244245
cmd := &cobra.Command{
245-
Use: "edit NAME",
246+
Use: "edit [NAME]",
246247
Short: "Edit a git integration",
247248
RunE: func(cmd *cobra.Command, args []string) error {
248-
if len(args) < 1 {
249-
return fmt.Errorf("missing integration name")
249+
if len(args) > 0 {
250+
opts.Name = &args[0]
250251
}
251252

252-
opts.Name = args[0]
253-
254253
opts.SharingPolicy = model.SharingPolicyAllUsersInAccount
255254
if accountAdminsOnly {
256255
opts.SharingPolicy = model.SharingPolicyAccountAdmins
@@ -310,15 +309,13 @@ func NewGitIntegrationRegisterCommand(client *sdk.AppProxyAPI) *cobra.Command {
310309
)
311310

312311
cmd := &cobra.Command{
313-
Use: "register NAME",
312+
Use: "register [NAME]",
314313
Short: "Register to a git integrations",
315314
RunE: func(cmd *cobra.Command, args []string) error {
316-
if len(args) < 1 {
317-
return fmt.Errorf("missing integration name")
315+
if len(args) > 0 {
316+
opts.Name = &args[0]
318317
}
319318

320-
opts.Name = args[0]
321-
322319
return RunGitIntegrationRegisterCommand(cmd.Context(), *client, &opts)
323320
},
324321
}
@@ -344,22 +341,26 @@ func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAP
344341
}
345342

346343
func NewGitIntegrationDeregisterCommand(client *sdk.AppProxyAPI) *cobra.Command {
344+
var (
345+
integration *string
346+
)
347+
347348
cmd := &cobra.Command{
348-
Use: "deregister NAME",
349+
Use: "deregister [NAME]",
349350
Short: "Deregister user from a git integrations",
350351
RunE: func(cmd *cobra.Command, args []string) error {
351-
if len(args) < 1 {
352-
return fmt.Errorf("missing integration name")
352+
if len(args) > 0 {
353+
integration = &args[0]
353354
}
354355

355-
return RunGitIntegrationDeregisterCommand(cmd.Context(), *client, args[0])
356+
return RunGitIntegrationDeregisterCommand(cmd.Context(), *client, integration)
356357
},
357358
}
358359

359360
return cmd
360361
}
361362

362-
func RunGitIntegrationDeregisterCommand(ctx context.Context, client sdk.AppProxyAPI, name string) error {
363+
func RunGitIntegrationDeregisterCommand(ctx context.Context, client sdk.AppProxyAPI, name *string) error {
363364
gi, err := client.GitIntegrations().Deregister(ctx, name)
364365
if err != nil {
365366
return fmt.Errorf("failed to deregister user from git integration: %w", err)
@@ -430,3 +431,11 @@ func verifyOutputFormat(format string, allowedFormats ...string) error {
430431

431432
return fmt.Errorf("invalid output format: %s", format)
432433
}
434+
435+
func parseGitProvider(provider string) (model.GitProviders, error) {
436+
p, ok := gitProvidersByName[provider]
437+
if !ok {
438+
return model.GitProviders(""), fmt.Errorf("provider '%s' is not a valid provider name", provider)
439+
}
440+
return p, nil
441+
}

cmd/commands/pipeline.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewPipelineGetCommand() *cobra.Command {
6262
RunE: func(cmd *cobra.Command, args []string) error {
6363
ctx := cmd.Context()
6464

65-
if err := verifyLatestVersion(ctx); err != nil {
65+
if err := verifyCLILatestVersion(ctx); err != nil {
6666
return err
6767
}
6868

@@ -101,7 +101,7 @@ func NewPipelineListCommand() *cobra.Command {
101101
RunE: func(cmd *cobra.Command, args []string) error {
102102
ctx := cmd.Context()
103103

104-
if err := verifyLatestVersion(ctx); err != nil {
104+
if err := verifyCLILatestVersion(ctx); err != nil {
105105
return err
106106
}
107107

0 commit comments

Comments
 (0)