func PathForBuild(build atc.Build) string { var path string if build.OneOff() { path, _ = Routes.CreatePathForRoute(GetJoblessBuild, rata.Params{ "build_id": fmt.Sprintf("%d", build.ID), }) } else { path, _ = Routes.CreatePathForRoute(GetBuild, rata.Params{ "pipeline_name": build.PipelineName, "job": build.JobName, "build": build.Name, }) } return path }
func Build(build db.Build) atc.Build { var err error var reqURL string if build.JobName == "" && build.PipelineName == "" { reqURL, err = web.Routes.CreatePathForRoute( web.GetJoblessBuild, rata.Params{"build_id": strconv.Itoa(build.ID)}, ) } else { reqURL, err = web.Routes.CreatePathForRoute( web.GetBuild, rata.Params{"job": build.JobName, "build": build.Name, "pipeline_name": build.PipelineName}, ) } if err != nil { panic("failed to generate url: " + err.Error()) } apiURL, err := atc.Routes.CreatePathForRoute(atc.GetBuild, rata.Params{"build_id": strconv.Itoa(build.ID)}) if err != nil { panic("failed to generate url: " + err.Error()) } atcBuild := atc.Build{ ID: build.ID, Name: build.Name, Status: string(build.Status), JobName: build.JobName, PipelineName: build.PipelineName, URL: reqURL, APIURL: apiURL, } if !build.StartTime.IsZero() { atcBuild.StartTime = build.StartTime.Unix() } if !build.EndTime.IsZero() { atcBuild.EndTime = build.EndTime.Unix() } return atcBuild }
package atc_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/concourse/atc" "github.com/concourse/atc/db" ) var _ = Describe("Build", func() { Describe("OneOff", func() { It("returns true if there is no JobName", func() { build := atc.Build{ JobName: "", } Expect(build.OneOff()).To(BeTrue()) }) It("returns false if there is a JobName", func() { build := atc.Build{ JobName: "something", } Expect(build.OneOff()).To(BeFalse()) }) }) Describe("IsRunning", func() { It("returns true if the build is pending", func() { build := atc.Build{ Status: string(atc.StatusPending),