Skip to content

Commit 4df2b26

Browse files
cli-v2 support (#18)
* cli-v2 support * wip * fix avatar field * undelete gitops use * wip
1 parent d48761f commit 4df2b26

File tree

9 files changed

+318
-14
lines changed

9 files changed

+318
-14
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.26.1
1+
0.26.2

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ require (
1111
github.com/spf13/afero v1.2.0 // indirect
1212
github.com/spf13/cobra v0.0.3
1313
github.com/spf13/viper v1.3.1
14+
github.com/stretchr/objx v0.3.0 // indirect
15+
github.com/stretchr/testify v1.3.0
1416
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
1517
gopkg.in/yaml.v2 v2.2.2
1618
)

go.sum

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
44
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
55
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
66
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
7+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
89
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
910
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
@@ -45,8 +46,12 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
4546
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
4647
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
4748
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
48-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
49+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
50+
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
51+
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
4952
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
53+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
54+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
5055
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
5156
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
5257
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

pkg/codefresh/codefresh.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ package codefresh
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/json"
67
"fmt"
7-
"github.com/google/go-querystring/query"
88
"io/ioutil"
99
"net/http"
1010
"strings"
11+
12+
"github.com/google/go-querystring/query"
1113
)
1214

15+
//go:generate mockery -name Codefresh -filename codefresh.go
16+
17+
//go:generate mockery -name UsersAPI -filename users.go
18+
1319
type (
1420
Codefresh interface {
1521
Pipelines() IPipelineAPI
@@ -19,6 +25,7 @@ type (
1925
Progresses() IProgressAPI
2026
Clusters() IClusterAPI
2127
Contexts() IContextAPI
28+
Users() UsersAPI
2229
Argo() ArgoAPI
2330
Gitops() GitopsAPI
2431
}
@@ -41,6 +48,10 @@ func (c *codefresh) Pipelines() IPipelineAPI {
4148
return newPipelineAPI(c)
4249
}
4350

51+
func (c *codefresh) Users() UsersAPI {
52+
return newUsersAPI(c)
53+
}
54+
4455
func (c *codefresh) Tokens() ITokenAPI {
4556
return newTokenAPI(c)
4657
}
@@ -74,6 +85,10 @@ func (c *codefresh) Gitops() GitopsAPI {
7485
}
7586

7687
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
88+
return c.requestAPIWithContext(context.Background(), opt)
89+
}
90+
91+
func (c *codefresh) requestAPIWithContext(ctx context.Context, opt *requestOptions) (*http.Response, error) {
7792
var body []byte
7893
finalURL := fmt.Sprintf("%s%s", c.host, opt.path)
7994
if opt.qs != nil {
@@ -82,7 +97,10 @@ func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
8297
if opt.body != nil {
8398
body, _ = json.Marshal(opt.body)
8499
}
85-
request, err := http.NewRequest(opt.method, finalURL, bytes.NewBuffer(body))
100+
request, err := http.NewRequestWithContext(ctx, opt.method, finalURL, bytes.NewBuffer(body))
101+
if err != nil {
102+
return nil, err
103+
}
86104
request.Header.Set("Authorization", c.token)
87105
request.Header.Set("Content-Type", "application/json")
88106

pkg/codefresh/contexts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type (
77
GetDefaultGitContext() (error, *ContextPayload)
88
}
99

10-
context struct {
10+
contexts struct {
1111
codefresh *codefresh
1212
}
1313

@@ -42,10 +42,10 @@ type (
4242
)
4343

4444
func newContextAPI(codefresh *codefresh) IContextAPI {
45-
return &context{codefresh}
45+
return &contexts{codefresh}
4646
}
4747

48-
func (c context) GetGitContexts() (error, *[]ContextPayload) {
48+
func (c contexts) GetGitContexts() (error, *[]ContextPayload) {
4949
var result []ContextPayload
5050

5151
qs := GitContextsQs{
@@ -67,7 +67,7 @@ func (c context) GetGitContexts() (error, *[]ContextPayload) {
6767
return err, &result
6868
}
6969

70-
func (c context) GetGitContextByName(name string) (error, *ContextPayload) {
70+
func (c contexts) GetGitContextByName(name string) (error, *ContextPayload) {
7171
var result ContextPayload
7272
var qs = map[string]string{
7373
"decrypt": "true",
@@ -87,7 +87,7 @@ func (c context) GetGitContextByName(name string) (error, *ContextPayload) {
8787
return nil, &result
8888
}
8989

90-
func (c context) GetDefaultGitContext() (error, *ContextPayload) {
90+
func (c contexts) GetDefaultGitContext() (error, *ContextPayload) {
9191
var result ContextPayload
9292

9393
resp, err := c.codefresh.requestAPI(&requestOptions{

pkg/codefresh/gitops.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,19 @@ type (
6969
Current int64 `json:"current"`
7070
Desired int64 `json:"desired"`
7171
}
72-
User struct {
73-
Name string `json:"name"`
74-
Avatar string `json:"avatar"`
75-
}
72+
7673
Annotation struct {
7774
Key string `json:"key"`
7875
Value string `json:"value"`
7976
}
8077

78+
GitopsUser struct {
79+
Name string `json:"name"`
80+
Avatar string `json:"avatar"`
81+
}
82+
8183
Gitops struct {
82-
Comitters []User `json:"comitters"`
84+
Comitters []GitopsUser `json:"comitters"`
8385
Prs []Annotation `json:"prs"`
8486
Issues []Annotation `json:"issues"`
8587
}

pkg/codefresh/mocks/codefresh.go

Lines changed: 173 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codefresh/mocks/users.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)