-
Notifications
You must be signed in to change notification settings - Fork 28
/
create.go
51 lines (39 loc) · 1.01 KB
/
create.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
// SPDX-License-Identifier: Apache-2.0
package pipeline
import (
"context"
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
)
// CreatePipeline creates a new pipeline in the database.
func (e *engine) CreatePipeline(ctx context.Context, p *api.Pipeline) (*api.Pipeline, error) {
e.logger.WithFields(logrus.Fields{
"pipeline": p.GetCommit(),
}).Tracef("creating pipeline %s in the database", p.GetCommit())
pipeline := types.PipelineFromAPI(p)
err := pipeline.Validate()
if err != nil {
return nil, err
}
err = pipeline.Compress(e.config.CompressionLevel)
if err != nil {
return nil, err
}
// send query to the database
err = e.client.
WithContext(ctx).
Table(constants.TablePipeline).
Create(pipeline).Error
if err != nil {
return nil, err
}
err = pipeline.Decompress()
if err != nil {
return nil, err
}
result := pipeline.ToAPI()
result.SetRepo(p.GetRepo())
return result, nil
}