github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/api/jobserver/get_build.go (about) 1 package jobserver 2 3 import ( 4 "encoding/json" 5 "net/http" 6 7 "github.com/pf-qiu/concourse/v6/atc/api/present" 8 "github.com/pf-qiu/concourse/v6/atc/db" 9 ) 10 11 func (s *Server) GetJobBuild(pipeline db.Pipeline) http.Handler { 12 logger := s.logger.Session("get-job-build") 13 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 14 jobName := r.FormValue(":job_name") 15 buildName := r.FormValue(":build_name") 16 17 job, found, err := pipeline.Job(jobName) 18 if err != nil { 19 logger.Error("failed-to-get-job", err) 20 w.WriteHeader(http.StatusInternalServerError) 21 return 22 } 23 24 if !found { 25 w.WriteHeader(http.StatusNotFound) 26 return 27 } 28 29 build, found, err := job.Build(buildName) 30 if err != nil { 31 logger.Error("failed-to-get-job-build", err) 32 w.WriteHeader(http.StatusInternalServerError) 33 return 34 } 35 36 if !found { 37 w.WriteHeader(http.StatusNotFound) 38 return 39 } 40 41 w.Header().Set("Content-Type", "application/json") 42 w.WriteHeader(http.StatusOK) 43 44 err = json.NewEncoder(w).Encode(present.Build(build)) 45 if err != nil { 46 logger.Error("failed-to-encode-build", err) 47 w.WriteHeader(http.StatusInternalServerError) 48 } 49 }) 50 }