-
Notifications
You must be signed in to change notification settings - Fork 28
/
update.go
41 lines (32 loc) · 1.07 KB
/
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
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: Apache-2.0
//nolint:dupl // ignore similar code with create.go
package build
import (
"context"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// UpdateBuild updates an existing build in the database.
func (e *engine) UpdateBuild(ctx context.Context, b *library.Build) (*library.Build, error) {
e.logger.WithFields(logrus.Fields{
"build": b.GetNumber(),
}).Tracef("updating build %d in the database", b.GetNumber())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#BuildFromLibrary
build := database.BuildFromLibrary(b)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Build.Validate
err := build.Validate()
if err != nil {
return nil, err
}
// crop build if any columns are too large
build = build.Crop()
// send query to the database
result := e.client.Table(constants.TableBuild).Save(build)
return build.ToLibrary(), result.Error
}