Skip to content

Commit 58b217b

Browse files
committed
Add GET endpoint and deserialize more info about builds
1 parent 1be6174 commit 58b217b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

pkg/codefresh/workflow.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,46 @@ import (
99
type (
1010
IWorkflowAPI interface {
1111
WaitForStatus(string, string, time.Duration, time.Duration) error
12+
Get(string) (*Workflow, error)
1213
}
1314

1415
workflow struct {
1516
codefresh Codefresh
1617
}
1718

1819
Workflow struct {
19-
ID string `json:"id"`
20-
Status string `json:"status"`
20+
ID string `json:"id"`
21+
Status string `json:"status"`
22+
UserYamlDescriptor string `json:"userYamlDescriptor"`
23+
Progress string `json:"progress"`
24+
Created time.Time `json:"created"`
25+
Updated time.Time `json:"updated"`
26+
Finished time.Time `json:"finished"`
2127
}
2228
)
2329

2430
func newWorkflowAPI(codefresh Codefresh) IWorkflowAPI {
2531
return &workflow{codefresh}
2632
}
2733

34+
func (w *workflow) Get(id string) (*Workflow, error) {
35+
wf := &Workflow{}
36+
resp, err := w.codefresh.requestAPI(&requestOptions{
37+
path: fmt.Sprintf("/api/builds/%s", id),
38+
method: "GET",
39+
})
40+
// failed in api call
41+
if err != nil {
42+
return nil, err
43+
}
44+
err = w.codefresh.decodeResponseInto(resp, wf)
45+
// failed to decode
46+
if err != nil {
47+
return nil, err
48+
}
49+
return wf, nil
50+
}
51+
2852
func (w *workflow) WaitForStatus(id string, status string, interval time.Duration, timeout time.Duration) error {
2953
err := waitFor(interval, timeout, func() (bool, error) {
3054

0 commit comments

Comments
 (0)