-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
api_buildlist.go
51 lines (45 loc) · 1.26 KB
/
api_buildlist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package yolosvc
import (
"context"
"fmt"
"berty.tech/yolo/v2/go/pkg/yolopb"
"berty.tech/yolo/v2/go/pkg/yolostore"
)
func (svc *service) BuildList(ctx context.Context, req *yolopb.BuildList_Request) (*yolopb.BuildList_Response, error) {
if req == nil {
req = &yolopb.BuildList_Request{}
}
if req.Limit == 0 {
req.Limit = 50
}
if !req.WithArtifacts {
req.WithArtifacts = len(req.ArtifactKinds) > 0
}
resp := yolopb.BuildList_Response{}
opts := yolostore.GetBuildListOpts{
ArtifactID: req.ArtifactID,
ArtifactKinds: req.ArtifactKinds,
WithArtifact: req.WithArtifacts,
BuildID: req.BuildID,
BuildState: req.BuildState,
BuildDriver: req.BuildDriver,
ProjectID: req.ProjectID,
MergeRequestID: req.MergeRequestID,
MergeRequestAuthorID: req.MergeRequestAuthorID,
MergeRequestState: req.MergerequestState,
Branch: req.Branch,
Limit: req.Limit,
}
var err error
resp.Builds, err = svc.store.GetBuildList(opts)
if err != nil {
return nil, err
}
// prepare response
for _, build := range resp.Builds {
if err := build.PrepareOutput(svc.authSalt); err != nil {
return nil, fmt.Errorf("failed preparing output")
}
}
return &resp, nil
}