internal/httpd/builds.go

650b235a4b9b5d89f728dfef9f388bb1904391ec
gitbay/internal/httpd/builds.go history · blame · raw

60 lines · 1404 bytes

 1package httpd
 2
 3import (
 4	"net/http"
 5	"strconv"
 6
 7	"gitbay.org/gitbay/internal/control"
 8)
 9
10func (s *Server) builds(w http.ResponseWriter, r *http.Request) {
11	p, ok := s.repoFor(w, r, "")
12	if !ok {
13		return
14	}
15	p.Tab = "builds"
16	viewer := s.webViewer(r)
17
18	var builds []control.BuildOut
19	s.runControlInto(viewer, []string{"build", "list", p.Repo.Path()}, &builds)
20
21	// The jobs a trigger can name. A repo without a CI config has none;
22	// that is not an error for this page.
23	var jobs []control.JobOut
24	s.runControlInto(viewer, []string{"build", "jobs", p.Repo.Path()}, &jobs)
25
26	s.render(w, "builds.html", struct {
27		repoPage
28		Builds   []control.BuildOut
29		Jobs     []control.JobOut
30		CanWrite bool
31		Notice   string
32	}{p, builds, jobs, s.canWriteRepo(r, p.Repo), s.takeFlash(w, r)})
33}
34
35func (s *Server) build(w http.ResponseWriter, r *http.Request) {
36	p, ok := s.repoFor(w, r, "")
37	if !ok {
38		return
39	}
40	p.Tab = "builds"
41	if _, err := strconv.ParseInt(r.PathValue("n"), 10, 64); err != nil {
42		s.notFound(w, r)
43		return
44	}
45	n := r.PathValue("n")
46	viewer := s.webViewer(r)
47
48	var b control.BuildOut
49	if _, ok := s.runControlInto(viewer, []string{"build", "show", p.Repo.Path(), n}, &b); !ok {
50		s.notFound(w, r)
51		return
52	}
53	log, _, _ := s.runControl(viewer, []string{"build", "log", p.Repo.Path(), n})
54
55	s.render(w, "build.html", struct {
56		repoPage
57		Build control.BuildOut
58		Log   string
59	}{p, b, log})
60}