forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
60 lines (49 loc) · 1.27 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
package triggerbuild
import (
"net/http"
"code.cloudfoundry.org/lager"
"github.com/tedsuo/rata"
"github.com/concourse/atc/web"
)
type Handler struct {
logger lager.Logger
clientFactory web.ClientFactory
}
func NewHandler(
logger lager.Logger,
clientFactory web.ClientFactory,
) *Handler {
return &Handler{
logger: logger,
clientFactory: clientFactory,
}
}
func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
client := handler.clientFactory.Build(r)
teamName := r.FormValue(":team_name")
pipelineName := r.FormValue(":pipeline_name")
jobName := r.FormValue(":job")
team := client.Team(teamName)
build, err := team.CreateJobBuild(pipelineName, jobName)
if err != nil {
handler.logger.Error("failed-to-create-build", err)
return err
}
redirectPath, err := web.Routes.CreatePathForRoute(web.GetBuild, rata.Params{
"team_name": teamName,
"pipeline_name": pipelineName,
"job": jobName,
"build": build.Name,
})
if err != nil {
handler.logger.Error("failed-to-construct-redirect-uri", err, lager.Data{
"team": teamName,
"pipeline": pipelineName,
"job": jobName,
"build": build.Name,
})
return err
}
http.Redirect(w, r, redirectPath, http.StatusFound)
return nil
}