-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathupdate.go
32 lines (25 loc) · 896 Bytes
/
update.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
// SPDX-License-Identifier: Apache-2.0
package deployment
import (
"context"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// UpdateDeployment updates an existing deployment in the database.
func (e *engine) UpdateDeployment(ctx context.Context, d *library.Deployment) (*library.Deployment, error) {
e.logger.WithFields(logrus.Fields{
"deployment": d.GetID(),
}).Tracef("updating deployment %d in the database", d.GetID())
// cast the library type to database type
deployment := database.DeploymentFromLibrary(d)
// validate the necessary fields are populated
err := deployment.Validate()
if err != nil {
return nil, err
}
result := e.client.Table(constants.TableDeployment).Save(deployment)
// send query to the database
return deployment.ToLibrary(d.Builds), result.Error
}