Skip to content

Commit 91f6dad

Browse files
list function
1 parent 243278f commit 91f6dad

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

pkg/codefresh/gitops.go

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package codefresh
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
6+
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
7+
)
48

59
type (
610
GitopsAPI interface {
@@ -10,6 +14,7 @@ type (
1014
GetEnvironments() ([]CFEnvironment, error)
1115
SendEvent(name string, props map[string]string) error
1216
SendApplicationResources(resources *ApplicationResources) error
17+
List(gitSources model.GitSource) ([]model.GitSource, error)
1318
}
1419

1520
gitops struct {
@@ -103,7 +108,7 @@ type (
103108
ParentApp string `json:"parentApp"`
104109
Namespace string `json:"namespace"`
105110
Server string `json:"server"`
106-
Context *string `json:"context"`
111+
Context *string `json:"context"`
107112
}
108113

109114
EnvironmentActivity struct {
@@ -119,7 +124,7 @@ type (
119124
HistoryId int64 `json:"historyId"`
120125
Revision string `json:"revision, omitempty"`
121126
Resources interface{} `json:"resources"`
122-
Context *string `json:"context"`
127+
Context *string `json:"context"`
123128
}
124129
)
125130

@@ -224,3 +229,59 @@ func (a *gitops) SendApplicationResources(resources *ApplicationResources) error
224229
}
225230
return nil
226231
}
232+
233+
func (a *gitops) List(gitSources model.GitSource) ([]model.GitSource, error) {
234+
jsonData := map[string]interface{}{
235+
"query": `
236+
{
237+
gitSources(pagination: {}, project: "") {
238+
edges {
239+
node {
240+
metadata {
241+
name
242+
}
243+
source {
244+
path
245+
}
246+
}
247+
}
248+
}
249+
}
250+
`,
251+
}
252+
253+
response, err := a.codefresh.requestAPI(&requestOptions{
254+
method: "POST",
255+
path: "/argo/api/graphql",
256+
body: jsonData,
257+
})
258+
if err != nil {
259+
fmt.Printf("The HTTP request failed with error %s\n", err)
260+
return nil, err
261+
}
262+
defer response.Body.Close()
263+
264+
// data, err := ioutil.ReadAll(response.Body)
265+
// if err != nil {
266+
// fmt.Printf("failed to read from response body")
267+
// return nil, err
268+
// }
269+
270+
// res := graphqlRuntimesResponse{}
271+
// err = json.Unmarshal(data, &res)
272+
273+
// if err != nil {
274+
// return nil, err
275+
// }
276+
277+
// gitSources := make([]model.GitSource, len(res.Data.Runtimes.Edges))
278+
// for i := range res.Data.Runtimes.Edges {
279+
// gitSources[i] = *res.Data.Runtimes.Edges[i].Node
280+
// }
281+
282+
// if len(res.Errors) > 0 {
283+
// return nil, graphqlErrorResponse{errors: res.Errors}
284+
// }
285+
286+
return nil, nil
287+
}

0 commit comments

Comments
 (0)