Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.26.1
0.26.2
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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/objx v0.3.0 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
gopkg.in/yaml.v2 v2.2.2
)
Expand Down
7 changes: 6 additions & 1 deletion 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 @@ -45,8 +46,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/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
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 Down
22 changes: 20 additions & 2 deletions pkg/codefresh/codefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package codefresh

import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/google/go-querystring/query"
"io/ioutil"
"net/http"
"strings"

"github.com/google/go-querystring/query"
)

//go:generate mockery -name Codefresh -filename codefresh.go

//go:generate mockery -name UsersAPI -filename users.go

type (
Codefresh interface {
Pipelines() IPipelineAPI
Expand All @@ -19,6 +25,7 @@ type (
Progresses() IProgressAPI
Clusters() IClusterAPI
Contexts() IContextAPI
Users() UsersAPI
Argo() ArgoAPI
Gitops() GitopsAPI
}
Expand All @@ -41,6 +48,10 @@ func (c *codefresh) Pipelines() IPipelineAPI {
return newPipelineAPI(c)
}

func (c *codefresh) Users() UsersAPI {
return newUsersAPI(c)
}

func (c *codefresh) Tokens() ITokenAPI {
return newTokenAPI(c)
}
Expand Down Expand Up @@ -74,6 +85,10 @@ func (c *codefresh) Gitops() GitopsAPI {
}

func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
return c.requestAPIWithContext(context.Background(), opt)
}

func (c *codefresh) requestAPIWithContext(ctx context.Context, opt *requestOptions) (*http.Response, error) {
var body []byte
finalURL := fmt.Sprintf("%s%s", c.host, opt.path)
if opt.qs != nil {
Expand All @@ -82,7 +97,10 @@ func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
if opt.body != nil {
body, _ = json.Marshal(opt.body)
}
request, err := http.NewRequest(opt.method, finalURL, bytes.NewBuffer(body))
request, err := http.NewRequestWithContext(ctx, opt.method, finalURL, bytes.NewBuffer(body))
if err != nil {
return nil, err
}
request.Header.Set("Authorization", c.token)
request.Header.Set("Content-Type", "application/json")

Expand Down
10 changes: 5 additions & 5 deletions pkg/codefresh/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type (
GetDefaultGitContext() (error, *ContextPayload)
}

context struct {
contexts struct {
codefresh *codefresh
}

Expand Down Expand Up @@ -42,10 +42,10 @@ type (
)

func newContextAPI(codefresh *codefresh) IContextAPI {
return &context{codefresh}
return &contexts{codefresh}
}

func (c context) GetGitContexts() (error, *[]ContextPayload) {
func (c contexts) GetGitContexts() (error, *[]ContextPayload) {
var result []ContextPayload

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

func (c context) GetGitContextByName(name string) (error, *ContextPayload) {
func (c contexts) GetGitContextByName(name string) (error, *ContextPayload) {
var result ContextPayload
var qs = map[string]string{
"decrypt": "true",
Expand All @@ -87,7 +87,7 @@ func (c context) GetGitContextByName(name string) (error, *ContextPayload) {
return nil, &result
}

func (c context) GetDefaultGitContext() (error, *ContextPayload) {
func (c contexts) GetDefaultGitContext() (error, *ContextPayload) {
var result ContextPayload

resp, err := c.codefresh.requestAPI(&requestOptions{
Expand Down
12 changes: 7 additions & 5 deletions pkg/codefresh/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,19 @@ type (
Current int64 `json:"current"`
Desired int64 `json:"desired"`
}
User struct {
Name string `json:"name"`
Avatar string `json:"avatar"`
}

Annotation struct {
Key string `json:"key"`
Value string `json:"value"`
}

GitopsUser struct {
Name string `json:"name"`
Avatar string `json:"avatar"`
}

Gitops struct {
Comitters []User `json:"comitters"`
Comitters []GitopsUser `json:"comitters"`
Prs []Annotation `json:"prs"`
Issues []Annotation `json:"issues"`
}
Expand Down
173 changes: 173 additions & 0 deletions pkg/codefresh/mocks/codefresh.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions pkg/codefresh/mocks/users.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading