Exemplo n.º 1
0
func PresentBuilds(builds []atc.Build) []PresentedBuild {
	presentedBuilds := []PresentedBuild{}

	for _, build := range builds {
		var cssClass string
		var jobName string
		var pipelineName string

		if build.JobName == "" {
			jobName = "[one off]"
			pipelineName = "[one off]"
			cssClass = "build-one-off"
		} else {
			jobName = build.JobName
			pipelineName = build.PipelineName
		}

		presentedBuilds = append(presentedBuilds, PresentedBuild{
			ID:           build.ID,
			JobName:      jobName,
			PipelineName: pipelineName,
			StartTime:    formatTime(build.StartTime),
			EndTime:      formatTime(build.EndTime),
			CSSClass:     cssClass,
			Status:       string(build.Status),
			Path:         web.PathForBuild(build),
		})
	}

	return presentedBuilds
}
Exemplo n.º 2
0
func PathFor(route string, args ...interface{}) (string, error) {
	switch route {
	case web.TriggerBuild:
		switch args[1].(type) {
		case atc.Job:
			return web.Routes.CreatePathForRoute(route, rata.Params{
				"pipeline_name": args[0].(string),
				"job":           jobName(args[1]),
			})
		default:
			return web.Routes.CreatePathForRoute(route, rata.Params{
				"pipeline_name": args[0].(string),
				"job":           jobName(args[1]),
			})
		}

	case web.GetResource:
		baseResourceURL, err := web.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name": args[0].(string),
			"resource":      resourceName(args[1]),
		})

		if err != nil {
			return "", err
		}

		if len(args) > 2 {
			page := args[2].(*concourse.Page)

			if page.Since != 0 {
				baseResourceURL += fmt.Sprintf("?since=%d", page.Since)
			} else {
				baseResourceURL += fmt.Sprintf("?until=%d", page.Until)
			}
		}

		return baseResourceURL, nil

	case web.GetBuilds:
		path, err := web.Routes.CreatePathForRoute(route, rata.Params{})
		if err != nil {
			return "", err
		}

		if len(args) > 0 {
			page := args[0].(*concourse.Page)

			if page.Since != 0 {
				path += fmt.Sprintf("?since=%d", page.Since)
			} else {
				path += fmt.Sprintf("?until=%d", page.Until)
			}
		}

		return path, nil

	case web.GetBuild:
		build := args[1].(atc.Build)
		build.JobName = jobName(args[0])
		return web.PathForBuild(build), nil

	case web.GetJoblessBuild:
		return web.PathForBuild(args[0].(atc.Build)), nil

	case web.Public:
		return web.Routes.CreatePathForRoute(route, rata.Params{
			"filename": args[0].(string),
		})

	case web.GetJob:
		baseJobURL, err := web.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name": args[0].(string),
			"job":           jobName(args[1]),
		})
		if err != nil {
			return "", err
		}

		if len(args) > 2 {
			page := args[2].(*concourse.Page)

			if page.Since != 0 {
				baseJobURL += fmt.Sprintf("?since=%d", page.Since)
			} else {
				baseJobURL += fmt.Sprintf("?until=%d", page.Until)
			}
		}

		return baseJobURL, nil

	case atc.BuildEvents:
		return atc.Routes.CreatePathForRoute(route, rata.Params{
			"build_id": fmt.Sprintf("%d", args[0].(atc.Build).ID),
		})

	case atc.EnableResourceVersion, atc.DisableResourceVersion:
		versionedResource := args[1].(atc.VersionedResource)

		return atc.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name":       args[0].(string),
			"resource_name":       fmt.Sprintf("%s", versionedResource.Resource),
			"resource_version_id": fmt.Sprintf("%d", versionedResource.ID),
		})

	case web.LogIn:
		return web.Routes.CreatePathForRoute(route, rata.Params{})

	case atc.DownloadCLI:
		path, err := atc.Routes.CreatePathForRoute(route, rata.Params{})
		if err != nil {
			return "", err
		}

		return path + "?" + url.Values{
			"platform": {args[0].(string)},
			"arch":     {args[1].(string)},
		}.Encode(), nil

	case auth.OAuthBegin:
		authPath, err := auth.OAuthRoutes.CreatePathForRoute(route, rata.Params{
			"provider": args[0].(string),
		})
		if err != nil {
			return "", err
		}

		return authPath + "?" + url.Values{
			"redirect": {args[1].(string)},
		}.Encode(), nil

	case web.BasicAuth:
		authPath, err := web.Routes.CreatePathForRoute(route, rata.Params{})
		if err != nil {
			return "", err
		}

		return authPath + "?" + url.Values{
			"redirect": {args[0].(string)},
		}.Encode(), nil
	}

	return "", fmt.Errorf("unknown route: %s", route)
}
Exemplo n.º 3
0
	"github.com/concourse/atc/web"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Routes", func() {
	Describe("PathForBuild", func() {
		It("returns the canonical path for a jobless build", func() {
			joblessBuild := db.Build{
				ID:           1,
				Name:         "23",
				PipelineName: "a-pipeline",
			}

			path := web.PathForBuild(joblessBuild)
			Expect(path).To(Equal("/builds/1"))
		})

		It("returns the canonical path for a job-filled build", func() {
			build := db.Build{
				ID:           1,
				JobName:      "hello",
				Name:         "23",
				PipelineName: "a-pipeline",
			}

			path := web.PathForBuild(build)
			Expect(path).To(Equal("/pipelines/a-pipeline/jobs/hello/builds/23"))
		})
	})