Example #1
0
File: handler.go Project: ACPK/atc
func FetchTemplateData(
	pipelineName string,
	client concourse.Client,
	jobName string,
	page concourse.Page,
) (TemplateData, error) {
	pipeline, pipelineFound, err := client.Pipeline(pipelineName)
	if err != nil {
		return TemplateData{}, err
	}

	if !pipelineFound {
		return TemplateData{}, ErrConfigNotFound
	}

	job, jobFound, err := client.Job(pipelineName, jobName)
	if err != nil {
		return TemplateData{}, err
	}

	if !jobFound {
		return TemplateData{}, ErrJobConfigNotFound
	}

	bs, pagination, _, err := client.JobBuilds(pipelineName, jobName, page)
	if err != nil {
		return TemplateData{}, err
	}

	var bsr []BuildWithInputsOutputs

	for _, build := range bs {
		buildInputsOutputs, _, err := client.BuildResources(build.ID)
		if err != nil {
			return TemplateData{}, err
		}

		bsr = append(bsr, BuildWithInputsOutputs{
			Build:     build,
			Resources: buildInputsOutputs,
		})
	}

	return TemplateData{
		PipelineName: pipelineName,
		Job:          job,

		Builds:     bsr,
		Pagination: pagination,

		GroupStates: group.States(pipeline.Groups, func(g atc.GroupConfig) bool {
			for _, groupJob := range g.Jobs {
				if groupJob == job.Name {
					return true
				}
			}

			return false
		}),

		CurrentBuild: job.FinishedBuild,
	}, nil
}