Skip to content

Commit

Permalink
implements the project list
Browse files Browse the repository at this point in the history
  • Loading branch information
janitha09 committed Apr 7, 2021
1 parent e8fde9c commit 1f27776
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.testFlags": ["-v"]
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/afero v1.2.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.1
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
gopkg.in/yaml.v2 v2.2.2
)
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
Expand Down Expand Up @@ -41,8 +42,12 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand All @@ -55,3 +60,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 4 additions & 0 deletions pkg/codefresh/codefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type (
Contexts() IContextAPI
Argo() ArgoAPI
Gitops() GitopsAPI
Projects() IProjectAPI
}
)

Expand Down Expand Up @@ -75,6 +76,9 @@ func (c *codefresh) Argo() ArgoAPI {
func (c *codefresh) Gitops() GitopsAPI {
return newGitopsAPI(c)
}
func (c *codefresh) Projects() IProjectAPI {
return newProjectAPI(c)
}

func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
var body []byte
Expand Down
38 changes: 38 additions & 0 deletions pkg/codefresh/project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package codefresh

type (
IProjectAPI interface {
List() ([]*Project, error)
}
project struct {
codefresh Codefresh
}
Project struct {
ProjectName string `json:"projectName"`
pipelineNumber int `json:"pipelineNumber"`
}
getProjectResponse struct {
Total int `json:"limit"`
Projects []*Project `json:"projects"`
}
)

func newProjectAPI(codefresh Codefresh) IProjectAPI {
return &project{codefresh}
}

func (p *project) List() ([]*Project, error) {
r := &getProjectResponse{}
resp, err := p.codefresh.requestAPI(&requestOptions{
path: "/api/projects",
method: "GET",
})
if err != nil {
return nil, err
}
err = p.codefresh.decodeResponseInto(resp, r)
if err != nil {
return nil, err
}
return r.Projects, nil
}
25 changes: 25 additions & 0 deletions pkg/codefresh/project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package codefresh

import (
"testing"

"github.com/stretchr/testify/assert"
)

var clientOptions = ClientOptions{
Auth: AuthOptions{
Token: "",
},
Debug: true,
Host: "https://g.codefresh.io",
}

func TestProject(t *testing.T) {

cf := New(&clientOptions)
projects, err := cf.Projects().List()
if err != nil {
t.Fatal(err)
}
assert.NotEqual(t, len(projects), 0)
}

0 comments on commit 1f27776

Please sign in to comment.