-
Notifications
You must be signed in to change notification settings - Fork 28
/
create.go
41 lines (32 loc) · 986 Bytes
/
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
// SPDX-License-Identifier: Apache-2.0
package step
import (
"context"
"github.com/sirupsen/logrus"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// CreateStep creates a new step in the database.
func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.Step, error) {
e.logger.WithFields(logrus.Fields{
"step": s.GetNumber(),
}).Tracef("creating step %s in the database", s.GetName())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary
step := database.StepFromLibrary(s)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Step.Validate
err := step.Validate()
if err != nil {
return nil, err
}
// send query to the database
result := e.client.
WithContext(ctx).
Table(constants.TableStep).
Create(step)
return step.ToLibrary(), result.Error
}