Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions cmd/commands/git-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ package commands
import (
"context"
"fmt"
"os"
"time"

"github.com/codefresh-io/cli-v2/pkg/log"
"github.com/codefresh-io/cli-v2/pkg/runtime"
"github.com/codefresh-io/cli-v2/pkg/store"
"github.com/codefresh-io/cli-v2/pkg/util"
"github.com/juju/ansiterm"

apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
Expand Down Expand Up @@ -66,6 +68,7 @@ func NewGitSourceCommand() *cobra.Command {
}

cmd.AddCommand(NewGitSourceCreateCommand())
cmd.AddCommand(NewGitSourceListCommand())
cmd.AddCommand(NewGitSourceDeleteCommand())

return cmd
Expand Down Expand Up @@ -132,6 +135,58 @@ func NewGitSourceCreateCommand() *cobra.Command {
return cmd
}

func NewGitSourceListCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list runtime_name",
Short: "List all Codefresh git-sources of a given runtime",
Example: util.Doc(`<BIN> git-source list my-runtime`),
RunE: func(_ *cobra.Command, args []string) error {
return RunGitSourceList(args[0])
},
}
return cmd
}

func RunGitSourceList(runtimeName string) error {
gitSources, err := cfConfig.NewClient().GitSource().List(runtimeName)

if err != nil {
return fmt.Errorf("failed to get git-sources list. Err: %w", err)
}

tb := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
_, err = fmt.Fprintln(tb, "NAME\tREPOURL\tPATH\tHEALTH-STATUS\tSYNC-STATUS")
if err != nil {
return fmt.Errorf("failed to print git-source list table headers. Err: %w", err)
}

for _, gs := range gitSources {
name := gs.Metadata.Name
repoURL := gs.Self.RepoURL
path := gs.Self.Path
healthStatus := "N/A"
syncStatus := gs.Self.Status.SyncStatus.String()

if gs.Self.Status.HealthStatus != nil {
healthStatus = gs.Self.Status.HealthStatus.String()
}

_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\n",
name,
repoURL,
path,
healthStatus,
syncStatus,
)

if err != nil {
return err
}
}

return tb.Flush()
}

func NewGitSourceDeleteCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
Expand Down
7 changes: 3 additions & 4 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
insCloneOpts.Parse()
if gsCloneOpts.Repo == "" {
host, orgRepo, _, _, _, suffix, _ := aputil.ParseGitUrl(insCloneOpts.Repo)
gsCloneOpts.Repo = host + orgRepo + "_git-source" + suffix + "/workflows"
gsCloneOpts.Repo = host + orgRepo + "_git-source" + suffix + "/resources"
}

gsCloneOpts.Parse()
Expand Down Expand Up @@ -293,13 +293,12 @@ func RunRuntimeList() error {
name := "N/A"
version := "N/A"

// make sure the go-sdk is returning the "self" reference
if rt.Self != nil && rt.Self.HealthMessage != nil {
status = *rt.Self.HealthMessage
}

if rt.Metadata.Namespace != "" {
namespace = rt.Metadata.Namespace
if rt.Metadata.Namespace != nil {
namespace = *rt.Metadata.Namespace
}

if rt.Cluster != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/argoproj/argo-events v1.3.1
github.com/argoproj/argo-workflows/v3 v3.1.0
github.com/briandowns/spinner v1.16.0
github.com/codefresh-io/go-sdk v0.31.1
github.com/codefresh-io/go-sdk v0.31.2
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-billy/v5 v5.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codefresh-io/go-sdk v0.31.1 h1:TvhQQ3wSCxa1UnIBTmKUCuNl0Uxwdc9Mxw/wzzjvQOo=
github.com/codefresh-io/go-sdk v0.31.1/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
github.com/codefresh-io/go-sdk v0.31.2 h1:uvkJoZ4mAUFnm+gosNJOOsT8gqRoftngJ5BmWlrzVWw=
github.com/codefresh-io/go-sdk v0.31.2/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
Expand Down