-
Notifications
You must be signed in to change notification settings - Fork 28
/
update.go
54 lines (44 loc) · 1.33 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
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: Apache-2.0
package pipeline
import (
"context"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// UpdatePipeline updates an existing pipeline in the database.
func (e *engine) UpdatePipeline(ctx context.Context, p *library.Pipeline) (*library.Pipeline, error) {
e.logger.WithFields(logrus.Fields{
"pipeline": p.GetCommit(),
}).Tracef("updating pipeline %s in the database", p.GetCommit())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#PipelineFromLibrary
pipeline := database.PipelineFromLibrary(p)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Pipeline.Validate
err := pipeline.Validate()
if err != nil {
return nil, err
}
// compress data for the pipeline
//
// https://pkg.go.dev/github.com/go-vela/types/database#Pipeline.Compress
err = pipeline.Compress(e.config.CompressionLevel)
if err != nil {
return nil, err
}
// send query to the database
err = e.client.Table(constants.TablePipeline).Save(pipeline).Error
if err != nil {
return nil, err
}
// decompress pipeline to return
err = pipeline.Decompress()
if err != nil {
return nil, err
}
return pipeline.ToLibrary(), nil
}