From 7e8a6762c8ef418b89a46ef19d158c16d6ce042e Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 4 Oct 2024 14:42:08 -0500 Subject: [PATCH] refactor: required changes from api build types migration --- api/types/build.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/api/types/build.go b/api/types/build.go index 10ccc31e2..a7f770125 100644 --- a/api/types/build.go +++ b/api/types/build.go @@ -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" ) @@ -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 +}