forked from concourse/concourse
/
get.go
68 lines (57 loc) · 1.47 KB
/
get.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package jobserver
import (
"encoding/json"
"net/http"
"github.com/chenbh/concourse/v6/atc/api/present"
"github.com/chenbh/concourse/v6/atc/db"
)
func (s *Server) GetJob(pipeline db.Pipeline) http.Handler {
logger := s.logger.Session("get-job")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
jobName := r.FormValue(":job_name")
job, found, err := pipeline.Job(jobName)
if err != nil {
logger.Error("could-not-get-job-finished", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
inputs, err := job.Inputs()
if err != nil {
logger.Error("could-not-get-job-inputs", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
outputs, err := job.Outputs()
if err != nil {
logger.Error("could-not-get-job-inputs", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
finished, next, err := job.FinishedAndNextBuild()
if err != nil {
logger.Error("could-not-get-job-finished-and-next-build", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
teamName := r.FormValue(":team_name")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(present.Job(
teamName,
job,
inputs,
outputs,
finished,
next,
nil,
))
if err != nil {
logger.Error("failed-to-encode-job", err)
w.WriteHeader(http.StatusInternalServerError)
}
})
}