forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
115 lines (91 loc) · 2.16 KB
/
handler.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package getbuild
import (
"html/template"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc"
"github.com/concourse/atc/web"
"github.com/concourse/atc/web/group"
)
type TemplateData struct {
GroupStates []group.State
TeamName string
PipelineName string
JobName string
Build atc.Build
}
type OldBuildTemplateData struct {
TemplateData
Builds []atc.Build
Inputs []atc.PublicBuildInput
}
type Handler struct {
logger lager.Logger
clientFactory web.ClientFactory
template *template.Template
}
func NewHandler(
logger lager.Logger,
clientFactory web.ClientFactory,
template *template.Template,
) *Handler {
return &Handler{
logger: logger,
clientFactory: clientFactory,
template: template,
}
}
func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
logger := handler.logger.Session("handler")
teamName := r.FormValue(":team_name")
pipelineName := r.FormValue(":pipeline_name")
jobName := r.FormValue(":job")
buildName := r.FormValue(":build")
client := handler.clientFactory.Build(r)
team := client.Team(teamName)
log := logger.Session("get-build", lager.Data{
"pipeline": pipelineName,
"job": jobName,
"build": buildName,
})
requestedBuild, found, err := team.JobBuild(pipelineName, jobName, buildName)
if err != nil {
log.Error("failed-to-get-build", err)
return err
}
if !found {
w.WriteHeader(http.StatusNotFound)
return nil
}
pipeline, found, err := team.Pipeline(pipelineName)
if err != nil {
log.Error("failed-to-get-pipeline", err)
return err
}
if !found {
w.WriteHeader(http.StatusNotFound)
return nil
}
templateData := TemplateData{
GroupStates: group.States(pipeline.Groups, func(g atc.GroupConfig) bool {
for _, groupJob := range g.Jobs {
if groupJob == jobName {
return true
}
}
return false
}),
TeamName: teamName,
PipelineName: pipelineName,
JobName: jobName,
Build: requestedBuild,
}
err = handler.template.Execute(w, templateData)
if err != nil {
log.Fatal("failed-to-build-template", err, lager.Data{
"template-data": templateData,
})
return err
}
return nil
}