Skip to content

Commit 1523907

Browse files
author
Oleg Sucharevich
authored
Merge pull request #8 from pchico83/progress
Support for progress GET endpoint
2 parents 3b55875 + ff7f2d4 commit 1523907

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.19.2
1+
0.19.3

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type (
1919
Tokens() ITokenAPI
2020
RuntimeEnvironments() IRuntimeEnvironmentAPI
2121
Workflows() IWorkflowAPI
22+
Progresses() IProgressAPI
2223
}
2324
)
2425

@@ -47,6 +48,10 @@ func (c *codefresh) Workflows() IWorkflowAPI {
4748
return newWorkflowAPI(c)
4849
}
4950

51+
func (c *codefresh) Progresses() IProgressAPI {
52+
return newProgressAPI(c)
53+
}
54+
5055
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
5156
var body []byte
5257
finalURL := fmt.Sprintf("%s%s", c.host, opt.path)

pkg/codefresh/progress.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package codefresh
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type (
8+
IProgressAPI interface {
9+
Get(string) (*Progress, error)
10+
}
11+
12+
progress struct {
13+
codefresh Codefresh
14+
}
15+
16+
Progress struct {
17+
ID string `json:"id"`
18+
Status string `json:"status"`
19+
Location Location `json:"location"`
20+
}
21+
22+
Location struct {
23+
Type string `json:"type"`
24+
URL string `json:"url"`
25+
}
26+
)
27+
28+
func newProgressAPI(codefresh Codefresh) IProgressAPI {
29+
return &progress{codefresh}
30+
}
31+
32+
func (p *progress) Get(id string) (*Progress, error) {
33+
result := &Progress{}
34+
resp, err := p.codefresh.requestAPI(&requestOptions{
35+
path: fmt.Sprintf("/api/progress/%s", id),
36+
method: "GET",
37+
})
38+
// failed in api call
39+
if err != nil {
40+
return nil, err
41+
}
42+
err = p.codefresh.decodeResponseInto(resp, result)
43+
// failed to decode
44+
if err != nil {
45+
return nil, err
46+
}
47+
return result, nil
48+
}

0 commit comments

Comments
 (0)