package httpd import ( "net/http" "strconv" "gitbay.org/gitbay/internal/ci" "gitbay.org/gitbay/internal/gitutil" "gitbay.org/gitbay/internal/store" ) func (s *Server) builds(w http.ResponseWriter, r *http.Request) { p, ok := s.repoFor(w, r, "") if !ok { return } p.Tab = "builds" builds, _ := s.st.ListBuilds(p.Repo.ID, 50) // The jobs a trigger can name come from the config on the default // branch, the same file the scheduler reads. var jobs []string if sha, err := gitutil.ResolveRef(p.Dir, "refs/heads/"+p.Repo.DefaultBranch); err == nil { if raw, err := gitutil.ReadBlob(p.Dir, sha, ci.ConfigPath, 1<<16); err == nil { if parsed, err := ci.Parse(raw); err == nil { for _, j := range parsed { jobs = append(jobs, j.Name) } } } } s.render(w, "builds.html", struct { repoPage Builds []store.Build Jobs []string CanWrite bool Notice string }{p, builds, jobs, s.canWriteRepo(r, p.Repo), r.URL.Query().Get("e")}) } func (s *Server) build(w http.ResponseWriter, r *http.Request) { p, ok := s.repoFor(w, r, "") if !ok { return } p.Tab = "builds" n, err := strconv.ParseInt(r.PathValue("n"), 10, 64) if err != nil { s.notFound(w, r) return } b, err := s.st.BuildByNumber(p.Repo.ID, n) if err != nil { s.notFound(w, r) return } log, _ := s.st.BuildLog(b.ID) s.render(w, "build.html", struct { repoPage Build store.Build Log string }{p, b, string(log)}) }