forked from vmware-archive/atc
/
list.go
41 lines (33 loc) · 928 Bytes
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package jobserver
import (
"encoding/json"
"net/http"
"github.com/concourse/atc"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) ListJobs(pipelineDB db.PipelineDB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var jobs []atc.Job
config, _, err := pipelineDB.GetConfig()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
for _, job := range config.Jobs {
finished, next, err := pipelineDB.GetJobFinishedAndNextBuild(job.Name)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
dbJob, err := pipelineDB.GetJob(job.Name)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
jobs = append(jobs, present.Job(dbJob, job, config.Groups, finished, next))
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(jobs)
})
}