Skip to content

Commit 1f27776

Browse files
committed
implements the project list
1 parent e8fde9c commit 1f27776

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"go.testFlags": ["-v"]
3+
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/spf13/afero v1.2.0 // indirect
1111
github.com/spf13/cobra v0.0.3
1212
github.com/spf13/viper v1.3.1
13+
github.com/stretchr/testify v1.7.0 // indirect
1314
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
1415
gopkg.in/yaml.v2 v2.2.2
1516
)

go.sum

+7
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=
@@ -41,8 +42,12 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
4142
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
4243
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
4344
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
45+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
46+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4447
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
4548
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
49+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
50+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4651
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
4752
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
4853
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -55,3 +60,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
5560
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5661
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
5762
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
63+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
64+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/codefresh/codefresh.go

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type (
2424
Contexts() IContextAPI
2525
Argo() ArgoAPI
2626
Gitops() GitopsAPI
27+
Projects() IProjectAPI
2728
}
2829
)
2930

@@ -75,6 +76,9 @@ func (c *codefresh) Argo() ArgoAPI {
7576
func (c *codefresh) Gitops() GitopsAPI {
7677
return newGitopsAPI(c)
7778
}
79+
func (c *codefresh) Projects() IProjectAPI {
80+
return newProjectAPI(c)
81+
}
7882

7983
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
8084
var body []byte

pkg/codefresh/project.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package codefresh
2+
3+
type (
4+
IProjectAPI interface {
5+
List() ([]*Project, error)
6+
}
7+
project struct {
8+
codefresh Codefresh
9+
}
10+
Project struct {
11+
ProjectName string `json:"projectName"`
12+
pipelineNumber int `json:"pipelineNumber"`
13+
}
14+
getProjectResponse struct {
15+
Total int `json:"limit"`
16+
Projects []*Project `json:"projects"`
17+
}
18+
)
19+
20+
func newProjectAPI(codefresh Codefresh) IProjectAPI {
21+
return &project{codefresh}
22+
}
23+
24+
func (p *project) List() ([]*Project, error) {
25+
r := &getProjectResponse{}
26+
resp, err := p.codefresh.requestAPI(&requestOptions{
27+
path: "/api/projects",
28+
method: "GET",
29+
})
30+
if err != nil {
31+
return nil, err
32+
}
33+
err = p.codefresh.decodeResponseInto(resp, r)
34+
if err != nil {
35+
return nil, err
36+
}
37+
return r.Projects, nil
38+
}

pkg/codefresh/project_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package codefresh
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
var clientOptions = ClientOptions{
10+
Auth: AuthOptions{
11+
Token: "",
12+
},
13+
Debug: true,
14+
Host: "https://g.codefresh.io",
15+
}
16+
17+
func TestProject(t *testing.T) {
18+
19+
cf := New(&clientOptions)
20+
projects, err := cf.Projects().List()
21+
if err != nil {
22+
t.Fatal(err)
23+
}
24+
assert.NotEqual(t, len(projects), 0)
25+
}

0 commit comments

Comments
 (0)