File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 1- 0.34.12
1+ 0.35.0
Original file line number Diff line number Diff line change 1+ package codefresh
2+
3+ import (
4+ "context"
5+ "fmt"
6+ )
7+
8+ type (
9+ ICliReleasesAPI interface {
10+ GetLatest (ctx context.Context ) (string , error )
11+ }
12+
13+ CliReleases struct {
14+ codefresh * codefresh
15+ }
16+
17+ graphQlGetLatestReleaseResponse struct {
18+ Data struct {
19+ LatestCliRelease string
20+ }
21+ Errors []graphqlError
22+ }
23+ )
24+
25+ func newCliReleasesAPI (codefresh * codefresh ) ICliReleasesAPI {
26+ return & CliReleases {codefresh : codefresh }
27+ }
28+
29+ func (releases * CliReleases ) GetLatest (ctx context.Context ) (string , error ) {
30+ jsonData := map [string ]interface {}{
31+ "query" : `{
32+ latestCliRelease
33+ }` ,
34+ }
35+
36+ res := graphQlGetLatestReleaseResponse {}
37+ err := releases .codefresh .graphqlAPI (ctx , jsonData , & res )
38+ if err != nil {
39+ return "" , fmt .Errorf ("failed making a graphql API call to runtime: %w" , err )
40+ }
41+
42+ if len (res .Errors ) > 0 {
43+ return "" , graphqlErrorResponse {errors : res .Errors }
44+ }
45+
46+ if res .Data .LatestCliRelease == "" {
47+ return "" , fmt .Errorf ("failed getting latest release" )
48+ }
49+
50+ return res .Data .LatestCliRelease , nil
51+ }
Original file line number Diff line number Diff line change 3838 Component () IComponentAPI
3939 Workflow () IWorkflowV2API
4040 Pipeline () IPipelineV2API
41+ CliReleases () ICliReleasesAPI
4142 }
4243)
4344
@@ -118,6 +119,10 @@ func (c *codefresh) Pipeline() IPipelineV2API {
118119 return newPipelineV2API (c )
119120}
120121
122+ func (c * codefresh ) CliReleases () ICliReleasesAPI {
123+ return newCliReleasesAPI (c )
124+ }
125+
121126func (c * codefresh ) requestAPI (opt * requestOptions ) (* http.Response , error ) {
122127 return c .requestAPIWithContext (context .Background (), opt )
123128}
You can’t perform that action at this time.
0 commit comments