Skip to content

Commit dc70f95

Browse files
Merge pull request #139 from codefresh-io/CR-6448
CR-6448
2 parents 6c128c0 + a0fef5c commit dc70f95

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.34.12
1+
0.35.0

pkg/codefresh/cli_releases.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type (
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+
121126
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
122127
return c.requestAPIWithContext(context.Background(), opt)
123128
}

0 commit comments

Comments
 (0)