Пример #1
0
func PathFor(route string, args ...interface{}) (string, error) {
	switch route {
	case routes.TriggerBuild:
		return routes.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name": args[0].(string),
			"job":           jobName(args[1]),
		})

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

	case routes.GetJoblessBuild:
		return routes.PathForBuild(args[0].(db.Build)), nil

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

	case routes.GetJob:
		return routes.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name": args[0].(string),
			"job":           args[1].(atc.JobConfig).Name,
		})

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

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

		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 routes.LogIn:
		return routes.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

	default:
		return "", fmt.Errorf("unknown route: %s", route)
	}
}
Пример #2
0
func PresentBuilds(builds []db.Build) []PresentedBuild {
	presentedBuilds := []PresentedBuild{}

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

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

		nilTime := time.Time{}
		if build.StartTime == nilTime {
			startTime = "failed to start"
		} else {
			startTime = formatDate(build.StartTime)
		}

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

	return presentedBuilds
}
Пример #3
0
func PathFor(route string, args ...interface{}) (string, error) {
	switch route {
	case routes.TriggerBuild:
		return routes.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name": args[0].(string),
			"job":           jobName(args[1]),
		})

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

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

		newer := args[3].(bool)
		paginationData := args[2].(getresource.PaginationData)

		if newer {
			baseResourceURL += "?id=" + strconv.Itoa(paginationData.NewerStartID) + "&newer=true"
		} else {
			baseResourceURL += "?id=" + strconv.Itoa(paginationData.OlderStartID) + "&newer=false"
		}

		return baseResourceURL, nil

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

	case routes.GetJoblessBuild:
		return routes.PathForBuild(args[0].(db.Build)), nil

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

	case routes.GetJob:
		return routes.Routes.CreatePathForRoute(route, rata.Params{
			"pipeline_name": args[0].(string),
			"job":           args[1].(atc.JobConfig).Name,
		})

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

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

		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 routes.LogIn:
		return routes.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

	default:
		return "", fmt.Errorf("unknown route: %s", route)
	}
}
Пример #4
0
	"github.com/concourse/atc/web/routes"

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

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

			path := routes.PathForBuild(joblessBuild)
			Ω(path).Should(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 := routes.PathForBuild(build)
			Ω(path).Should(Equal("/pipelines/a-pipeline/jobs/hello/builds/23"))
		})
	})