Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: required changes from api build types migration #1204

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions api/types/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"time"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/types/raw"
)

Expand Down Expand Up @@ -1205,3 +1207,38 @@ func (b *Build) String() string {
b.GetTitle(),
)
}

// StepFromBuildContainer creates a new Step based on a Build and pipeline Container.
func StepFromBuildContainer(build *Build, ctn *pipeline.Container) *library.Step {
// create new step type we want to return
s := new(library.Step)

// default status to Pending
s.SetStatus(constants.StatusPending)

// copy fields from build
if build != nil {
// set values from the build
s.SetHost(build.GetHost())
s.SetRuntime(build.GetRuntime())
s.SetDistribution(build.GetDistribution())
}

// copy fields from container
if ctn != nil && ctn.Name != "" {
// set values from the container
s.SetName(ctn.Name)
s.SetNumber(ctn.Number)
s.SetImage(ctn.Image)
s.SetReportAs(ctn.ReportAs)

// check if the VELA_STEP_STAGE environment variable exists
value, ok := ctn.Environment["VELA_STEP_STAGE"]
if ok {
// set the Stage field to the value from environment variable
s.SetStage(value)
}
}

return s
}
Loading