Skip to content

Commit aebc44c

Browse files
CR-6234-repo-url (#123)
* add ensureRepo * add Repo to createNewRunTimeOnPlatform * ensureRepo on git-source * - ensureRepo for git-source commands - adjust gitSources fields to the sdk update (on git-source list command) * bump version
1 parent 86af48b commit aebc44c

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

cmd/commands/common.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ package commands
1616

1717
import (
1818
_ "embed"
19+
"fmt"
1920
"os"
2021
"regexp"
2122

23+
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
2224
"github.com/codefresh-io/cli-v2/pkg/config"
2325
"github.com/codefresh-io/cli-v2/pkg/util"
2426

@@ -58,3 +60,18 @@ func presetRequiredFlags(cmd *cobra.Command) {
5860
func IsValid(s string) (bool, error) {
5961
return regexp.MatchString(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`, s)
6062
}
63+
64+
func ensureRepo(cmd *cobra.Command, args []string, cloneOpts *git.CloneOptions) error {
65+
ctx := cmd.Context()
66+
if cloneOpts.Repo == "" {
67+
runtimeData, err := cfConfig.NewClient().V2().Runtime().Get(ctx, args[0])
68+
if err != nil {
69+
return fmt.Errorf("Failed getting runtime repo information: %w", err)
70+
}
71+
if runtimeData.Repo != nil {
72+
cloneOpts.Repo = *runtimeData.Repo
73+
die(cmd.Flags().Set("repo", *runtimeData.Repo))
74+
}
75+
}
76+
return nil
77+
}

cmd/commands/git-source.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
119119
Example: util.Doc(`
120120
<BIN> git-source create runtime_name git-source-name --git-src-repo https://github.com/owner/repo-name/my-workflow
121121
`),
122-
PreRun: func(cmd *cobra.Command, args []string) {
122+
PreRunE: func(cmd *cobra.Command, args []string) error {
123123
ctx := cmd.Context()
124124

125125
if len(args) < 1 {
@@ -133,6 +133,11 @@ func NewGitSourceCreateCommand() *cobra.Command {
133133
if gsCloneOpts.Repo == "" {
134134
log.G(ctx).Fatal("must enter a valid value to --git-src-repo. Example: https://github.com/owner/repo-name/path/to/workflow")
135135
}
136+
137+
err := ensureRepo(cmd, args, insCloneOpts)
138+
if err != nil {
139+
return err
140+
}
136141

137142
isValid, err := IsValid(args[1])
138143
if err != nil {
@@ -149,6 +154,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
149154

150155
insCloneOpts.Parse()
151156
gsCloneOpts.Parse()
157+
return nil
152158
},
153159
RunE: func(cmd *cobra.Command, args []string) error {
154160
ctx := cmd.Context()
@@ -396,15 +402,23 @@ func RunGitSourceList(ctx context.Context, runtimeName string) error {
396402

397403
for _, gs := range gitSources {
398404
name := gs.Metadata.Name
399-
repoURL := gs.Self.RepoURL
400-
path := gs.Self.Path
405+
repoURL := "N/A"
406+
path := "N/A"
401407
healthStatus := "N/A"
402408
syncStatus := gs.Self.Status.SyncStatus.String()
403409

404410
if gs.Self.Status.HealthStatus != nil {
405411
healthStatus = gs.Self.Status.HealthStatus.String()
406412
}
407413

414+
if gs.Self.RepoURL != nil {
415+
repoURL = *gs.Self.RepoURL
416+
}
417+
418+
if gs.Self.Path != nil {
419+
path = *gs.Self.Path
420+
}
421+
408422
_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\n",
409423
name,
410424
repoURL,
@@ -432,7 +446,7 @@ func NewGitSourceDeleteCommand() *cobra.Command {
432446
Example: util.Doc(`
433447
<BIN> git-source delete runtime_name git-source_name
434448
`),
435-
PreRun: func(cmd *cobra.Command, args []string) {
449+
PreRunE: func(cmd *cobra.Command, args []string) error {
436450
ctx := cmd.Context()
437451

438452
if len(args) < 1 {
@@ -443,7 +457,13 @@ func NewGitSourceDeleteCommand() *cobra.Command {
443457
log.G(ctx).Fatal("must enter git-source name")
444458
}
445459

460+
err := ensureRepo(cmd, args, insCloneOpts)
461+
if err != nil {
462+
return err
463+
}
464+
446465
insCloneOpts.Parse()
466+
return nil
447467
},
448468
RunE: func(cmd *cobra.Command, args []string) error {
449469
ctx := cmd.Context()
@@ -491,7 +511,7 @@ func NewGitSourceEditCommand() *cobra.Command {
491511
Example: util.Doc(`
492512
<BIN> git-source edit runtime_name git-source_name --git-src-repo https://github.com/owner/repo-name/my-workflow
493513
`),
494-
PreRun: func(cmd *cobra.Command, args []string) {
514+
PreRunE: func(cmd *cobra.Command, args []string) error {
495515
ctx := cmd.Context()
496516

497517
if len(args) < 1 {
@@ -506,8 +526,14 @@ func NewGitSourceEditCommand() *cobra.Command {
506526
log.G(ctx).Fatal("must enter a valid value to --git-src-repo. Example: https://github.com/owner/repo-name/path/to/workflow")
507527
}
508528

529+
err := ensureRepo(cmd, args, insCloneOpts)
530+
if err != nil {
531+
return err
532+
}
533+
509534
insCloneOpts.Parse()
510535
gsCloneOpts.Parse()
536+
return nil
511537
},
512538
RunE: func(cmd *cobra.Command, args []string) error {
513539
ctx := cmd.Context()

cmd/commands/runtime.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
264264
RuntimeVersion: runtimeVersion,
265265
IngressHost: &opts.IngressHost,
266266
ComponentNames: componentNames,
267+
Repo: &opts.InsCloneOpts.Repo,
267268
})
268269
if err != nil {
269270
return fmt.Errorf("failed to create a new runtime: %w", err)
@@ -576,8 +577,13 @@ func NewRuntimeUninstallCommand() *cobra.Command {
576577
577578
<BIN> runtime uninstall runtime-name --repo gitops_repo
578579
`),
579-
PreRun: func(_ *cobra.Command, _ []string) {
580+
PreRunE: func(cmd *cobra.Command, args []string) error {
581+
err := ensureRepo(cmd, args, cloneOpts)
582+
if err != nil {
583+
return err
584+
}
580585
cloneOpts.Parse()
586+
return nil
581587
},
582588
RunE: func(cmd *cobra.Command, args []string) error {
583589
ctx := cmd.Context()
@@ -658,8 +664,13 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
658664
659665
<BIN> runtime upgrade runtime-name --version 0.0.30 --repo gitops_repo
660666
`),
661-
PreRun: func(_ *cobra.Command, _ []string) {
667+
PreRunE: func(cmd *cobra.Command, args []string) error {
668+
err := ensureRepo(cmd, args, cloneOpts)
669+
if err != nil {
670+
return err
671+
}
662672
cloneOpts.Parse()
673+
return nil
663674
},
664675
RunE: func(cmd *cobra.Command, args []string) error {
665676
var (

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v1.4.0
1111
github.com/argoproj/argo-workflows/v3 v3.1.6
1212
github.com/briandowns/spinner v1.16.0
13-
github.com/codefresh-io/go-sdk v0.34.10
13+
github.com/codefresh-io/go-sdk v0.34.12
1414
github.com/fatih/color v1.12.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w
262262
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
263263
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
264264
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
265-
github.com/codefresh-io/go-sdk v0.34.10 h1:C+wH3rKRT+c/ePmdCuKA6YY2bEmIV1P/pIE9S5QS1AU=
266-
github.com/codefresh-io/go-sdk v0.34.10/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
265+
github.com/codefresh-io/go-sdk v0.34.12 h1:cwUa1DD4yQ16xuUDHRik6M5GK+I2xkX2ADWNCnsQkOM=
266+
github.com/codefresh-io/go-sdk v0.34.12/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
267267
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
268268
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
269269
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=

0 commit comments

Comments
 (0)