Skip to content

Commit

Permalink
refactor: required changes from api build types migration
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 4, 2024
1 parent 248b3a3 commit 7e8a676
Showing 1 changed file with 37 additions and 0 deletions.
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
}

0 comments on commit 7e8a676

Please sign in to comment.