forked from vmware-archive/atc
/
get_build.go
45 lines (36 loc) · 959 Bytes
/
get_build.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
42
43
44
45
package jobserver
import (
"encoding/json"
"net/http"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) GetJobBuild(pipeline db.Pipeline) http.Handler {
logger := s.logger.Session("get-job-build")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
jobName := r.FormValue(":job_name")
buildName := r.FormValue(":build_name")
job, found, err := pipeline.Job(jobName)
if err != nil {
logger.Error("failed-to-get-job", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
build, found, err := job.Build(buildName)
if err != nil {
logger.Error("failed-to-get-job-build", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(present.Build(build))
})
}