Skip to content

Commit d953546

Browse files
CR-4371-gs-list-3 (#62)
* . * . * list log * . * without local gosdk * . * fields * erased redundant * tidy * tidy * bump * lint * added * .
1 parent 955be07 commit d953546

File tree

9 files changed

+99
-12
lines changed

9 files changed

+99
-12
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.65
1+
VERSION=v0.0.66
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/git-source.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ package commands
1717
import (
1818
"context"
1919
"fmt"
20+
"os"
2021
"time"
2122

2223
"github.com/codefresh-io/cli-v2/pkg/log"
2324
"github.com/codefresh-io/cli-v2/pkg/runtime"
2425
"github.com/codefresh-io/cli-v2/pkg/store"
2526
"github.com/codefresh-io/cli-v2/pkg/util"
27+
"github.com/juju/ansiterm"
2628

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

6870
cmd.AddCommand(NewGitSourceCreateCommand())
71+
cmd.AddCommand(NewGitSourceListCommand())
6972
cmd.AddCommand(NewGitSourceDeleteCommand())
7073

7174
return cmd
@@ -132,6 +135,58 @@ func NewGitSourceCreateCommand() *cobra.Command {
132135
return cmd
133136
}
134137

138+
func NewGitSourceListCommand() *cobra.Command {
139+
cmd := &cobra.Command{
140+
Use: "list runtime_name",
141+
Short: "List all Codefresh git-sources of a given runtime",
142+
Example: util.Doc(`<BIN> git-source list my-runtime`),
143+
RunE: func(_ *cobra.Command, args []string) error {
144+
return RunGitSourceList(args[0])
145+
},
146+
}
147+
return cmd
148+
}
149+
150+
func RunGitSourceList(runtimeName string) error {
151+
gitSources, err := cfConfig.NewClient().GitSource().List(runtimeName)
152+
153+
if err != nil {
154+
return fmt.Errorf("failed to get git-sources list. Err: %w", err)
155+
}
156+
157+
tb := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
158+
_, err = fmt.Fprintln(tb, "NAME\tREPOURL\tPATH\tHEALTH-STATUS\tSYNC-STATUS")
159+
if err != nil {
160+
return fmt.Errorf("failed to print git-source list table headers. Err: %w", err)
161+
}
162+
163+
for _, gs := range gitSources {
164+
name := gs.Metadata.Name
165+
repoURL := gs.Self.RepoURL
166+
path := gs.Self.Path
167+
healthStatus := "N/A"
168+
syncStatus := gs.Self.Status.SyncStatus.String()
169+
170+
if gs.Self.Status.HealthStatus != nil {
171+
healthStatus = gs.Self.Status.HealthStatus.String()
172+
}
173+
174+
_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\n",
175+
name,
176+
repoURL,
177+
path,
178+
healthStatus,
179+
syncStatus,
180+
)
181+
182+
if err != nil {
183+
return err
184+
}
185+
}
186+
187+
return tb.Flush()
188+
}
189+
135190
func NewGitSourceDeleteCommand() *cobra.Command {
136191
var (
137192
cloneOpts *git.CloneOptions
@@ -182,7 +237,6 @@ func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error
182237
}
183238

184239
fi, err := gsFs.ReadDir(".")
185-
186240
if err != nil {
187241
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
188242
}

cmd/commands/runtime.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
125125
insCloneOpts.Parse()
126126
if gsCloneOpts.Repo == "" {
127127
host, orgRepo, _, _, _, suffix, _ := aputil.ParseGitUrl(insCloneOpts.Repo)
128-
gsCloneOpts.Repo = host + orgRepo + "_git-source" + suffix + "/workflows"
128+
gsCloneOpts.Repo = host + orgRepo + "_git-source" + suffix + "/resources"
129129
}
130130

131131
gsCloneOpts.Parse()
@@ -293,13 +293,12 @@ func RunRuntimeList() error {
293293
name := "N/A"
294294
version := "N/A"
295295

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

301-
if rt.Metadata.Namespace != "" {
302-
namespace = rt.Metadata.Namespace
300+
if rt.Metadata.Namespace != nil {
301+
namespace = *rt.Metadata.Namespace
303302
}
304303

305304
if rt.Cluster != nil {

docs/commands/cli-v2_git-source.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ cli-v2 git-source [flags]
2626
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
2727
* [cli-v2 git-source create](cli-v2_git-source_create.md) - add a new git-source to an existing runtime
2828
* [cli-v2 git-source delete](cli-v2_git-source_delete.md) - delete a git-source from a runtime
29+
* [cli-v2 git-source list](cli-v2_git-source_list.md) - List all Codefresh git-sources of a given runtime
2930

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## cli-v2 git-source list
2+
3+
List all Codefresh git-sources of a given runtime
4+
5+
```
6+
cli-v2 git-source list runtime_name [flags]
7+
```
8+
9+
### Examples
10+
11+
```
12+
cli-v2 git-source list my-runtime
13+
```
14+
15+
### Options
16+
17+
```
18+
-h, --help help for list
19+
```
20+
21+
### Options inherited from parent commands
22+
23+
```
24+
--auth-context string Run the next command using a specific authentication context
25+
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
26+
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
27+
--request-timeout duration Request timeout (default 30s)
28+
```
29+
30+
### SEE ALSO
31+
32+
* [cli-v2 git-source](cli-v2_git-source.md) - Manage git-sources of Codefresh runtimes
33+

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.65/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.66/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.65/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.66/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

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.3.1
1111
github.com/argoproj/argo-workflows/v3 v3.1.0
1212
github.com/briandowns/spinner v1.16.0
13-
github.com/codefresh-io/go-sdk v0.31.1
13+
github.com/codefresh-io/go-sdk v0.31.2
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
@@ -269,8 +269,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
269269
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
270270
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
271271
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
272-
github.com/codefresh-io/go-sdk v0.31.1 h1:TvhQQ3wSCxa1UnIBTmKUCuNl0Uxwdc9Mxw/wzzjvQOo=
273-
github.com/codefresh-io/go-sdk v0.31.1/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
272+
github.com/codefresh-io/go-sdk v0.31.2 h1:uvkJoZ4mAUFnm+gosNJOOsT8gqRoftngJ5BmWlrzVWw=
273+
github.com/codefresh-io/go-sdk v0.31.2/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
274274
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
275275
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
276276
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.65
8+
version: 0.0.66
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)