-
Notifications
You must be signed in to change notification settings - Fork 28
/
get.go
56 lines (45 loc) · 1.17 KB
/
get.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
52
53
54
55
56
// SPDX-License-Identifier: Apache-2.0
package deployment
import (
"context"
"strconv"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// GetDeployment gets a deployment by ID from the database.
func (e *engine) GetDeployment(ctx context.Context, id int64) (*library.Deployment, error) {
e.logger.Tracef("getting deployment %d from the database", id)
// variable to store query results
d := new(database.Deployment)
// send query to the database and store result in variable
err := e.client.
Table(constants.TableDeployment).
Where("id = ?", id).
Take(d).
Error
if err != nil {
return nil, err
}
builds := []*library.Build{}
for _, a := range d.Builds {
bID, err := strconv.ParseInt(a, 10, 64)
if err != nil {
return nil, err
}
// variable to store query results
b := new(database.Build)
// send query to the database and store result in variable
err = e.client.
Table(constants.TableBuild).
Where("id = ?", bID).
Take(b).
Error
if err != nil {
return nil, err
}
builds = append(builds, b.ToLibrary())
}
// return the deployment
return d.ToLibrary(builds), nil
}