// clHandler serves the HTML for the /cl/<id> page. // // These are shortcuts to individual clusters. // // See alertingHandler for the JSON it uses. // func clHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") if *local { loadTemplates() } match := clHandlerPath.FindStringSubmatch(r.URL.Path) if r.Method != "GET" || match == nil || len(match) != 2 { http.NotFound(w, r) return } id, err := strconv.ParseInt(match[1], 10, 0) if err != nil { util.ReportError(w, r, err, "Failed parsing ID.") return } cl, err := alerting.Get(id) if err != nil { util.ReportError(w, r, err, "Failed to find cluster with that ID.") return } if err := templates.ExecuteTemplate(w, "cl.html", cl); err != nil { glog.Errorln("Failed to expand template:", err) } }
// activityHandler serves the HTML for the /activitylog/ page. // // If an optional number n is appended to the path, returns the most recent n // activities. Otherwise returns the most recent 100 results. // func activityHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") if *local { loadTemplates() } match := activityHandlerPath.FindStringSubmatch(r.URL.Path) if r.Method != "GET" || match == nil || len(match) != 2 { http.NotFound(w, r) return } n := 100 if len(match[1]) > 0 { num, err := strconv.ParseInt(match[1], 10, 0) if err != nil { util.ReportError(w, r, err, "Failed parsing the given number.") return } n = int(num) } a, err := activitylog.GetRecent(n) if err != nil { util.ReportError(w, r, err, "Failed to retrieve activity.") return } if err := templates.ExecuteTemplate(w, "activitylog.html", a); err != nil { glog.Errorln("Failed to expand template:", err) } }
// clustersHandler handles the GET of the clusters page. func clustersHandler(w http.ResponseWriter, r *http.Request) { glog.Infof("Cluster Handler: %q\n", r.URL.Path) w.Header().Set("Content-Type", "text/html") if err := clusterTemplate.Execute(w, nil); err != nil { glog.Errorln("Failed to expand template:", err) } }
// mainHandler handles the GET of the main page. func mainHandler(w http.ResponseWriter, r *http.Request) { glog.Infof("Main Handler: %q\n", r.URL.Path) if r.Method == "GET" { w.Header().Set("Content-Type", "text/html") if err := indexTemplate.Execute(w, struct{}{}); err != nil { glog.Errorln("Failed to expand template:", err) } } }
// helpHandler handles the GET of the main page. func helpHandler(w http.ResponseWriter, r *http.Request) { glog.Infof("Help Handler: %q\n", r.URL.Path) if r.Method == "GET" { w.Header().Set("Content-Type", "text/html") ctx := parser.NewContext(nil) if err := helpTemplate.Execute(w, ctx); err != nil { glog.Errorln("Failed to expand template:", err) } } }
// mainHandler handles the GET of the main page. func mainHandler(w http.ResponseWriter, r *http.Request) { if *local { loadTemplates() } if r.Method == "GET" { w.Header().Set("Content-Type", "text/html") if err := indexTemplate.Execute(w, struct{}{}); err != nil { glog.Errorln("Failed to expand template:", err) } } }
func templateHandler(name string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") if *local { loadTemplates() } if err := templates.ExecuteTemplate(w, name, struct{}{}); err != nil { glog.Errorln("Failed to expand template:", err) } } }
func rulesHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") // Don't use cached templates in testing mode. if *testing { reloadTemplates() } if err := rulesTemplate.Execute(w, struct{}{}); err != nil { glog.Errorln("Failed to expand template:", err) } }
// alertResetHandler deletes all the non-Bug alerts. // func alertResetHandler(w http.ResponseWriter, r *http.Request) { glog.Infof("AlertResetHandler: %q\n", r.URL.Path) if login.LoggedInAs(r) == "" { util.ReportError(w, r, fmt.Errorf("Not logged in."), "You must be logged in to change an alert status.") return } if r.Method != "POST" { http.NotFound(w, r) return } if err := alerting.Reset(); err != nil { glog.Errorln("Failed to delete all non-Bug alerts:", err) } http.Redirect(w, r, "/alerts/", 303) }
func mainHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") // Don't use cached templates in testing mode. if *testing { reloadTemplates() } mainPage := struct { ProjectName string ProjectUser string }{ ProjectName: *childName, ProjectUser: arb.User(), } if err := mainTemplate.Execute(w, mainPage); err != nil { glog.Errorln("Failed to expand template:", err) } }
// mainHandler handles the GET of the main page. func mainHandler(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { if *local { loadResouces() } units, err := listUnits() if err != nil { util.ReportError(w, r, err, "Failed to list units.") return } context := &IndexBody{ Hostname: hostname, Units: units, } w.Header().Set("Content-Type", "text/html") if err := indexTemplate.ExecuteTemplate(w, "index.html", context); err != nil { glog.Errorln("Failed to expand template:", err) } } }
func search2Handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") if *local { loadTemplates() } digests, numMatches, commits, err := search.Search(queryFromRequest(r), storages, tallies, blamer, paramsetSum) if err != nil { util.ReportError(w, r, err, "Search for digests failed.") } js, err := json.MarshalIndent(digests, "", " ") if err != nil { util.ReportError(w, r, err, "Failed to encode response data.") return } commitsjs, err := json.MarshalIndent(commits, "", " ") if err != nil { util.ReportError(w, r, err, "Failed to encode commits.") return } context := struct { Digests []*search.Digest JS template.JS CommitsJS template.JS NumMatches int }{ Digests: digests, JS: template.JS(string(js)), CommitsJS: template.JS(string(commitsjs)), NumMatches: numMatches, } if err := templates.ExecuteTemplate(w, "search2.html", context); err != nil { glog.Errorln("Failed to expand template:", err) } }
// mainHandler handles the GET of the main page. // // Handles servering all the processed Markdown documents // and other assetts in the doc repo. func mainHandler(w http.ResponseWriter, r *http.Request) { glog.Infof("Main Handler: %q\n", r.URL.Path) // If the request begins with /_/ then it is an XHR request and we only need // to return the content and not the surrounding markup. bodyOnly := false if strings.HasPrefix(r.URL.Path, "/_/") { bodyOnly = true r.URL.Path = r.URL.Path[2:] } d := primary // If there is a cl={issue_number} query parameter supplied then // clone a new copy of the docs repo and patch that issue into it, // and then serve this reqeust from that patched repo. cl := r.FormValue("cl") if cl != "" { issue, err := strconv.ParseInt(cl, 10, 64) if err != nil { util.ReportError(w, r, err, "The CL given is not valid.") return } d, err = docset.NewDocSetForIssue(filepath.Join(*workDir, "patches"), filepath.Join(*workDir, "primary"), issue) if err != nil { util.ReportError(w, r, err, "Failed to load the given CL") return } } // When running in local mode reload all templates and rebuild the navigation // menu on every request, so we don't have to start and stop the server while // developing. if *local { d.BuildNavigation() loadTemplates() } filename, raw, err := d.RawFilename(r.URL.Path) if err != nil { glog.Infof("Request for unknown path: %s", r.URL.Path) http.NotFound(w, r) return } // Set the content type. mimetype := "text/html" if raw { mimetype = mime.TypeByExtension(filepath.Ext(filename)) } w.Header().Set("Content-Type", mimetype) // Write the response. b, err := d.Body(filename) if err != nil { util.ReportError(w, r, err, "Failed to load file") return } if raw { if _, err := w.Write(b); err != nil { glog.Errorf("Failed to write output: %s", err) return } } else { body := blackfriday.MarkdownCommon(b) if bodyOnly { if _, err := w.Write(body); err != nil { glog.Errorf("Failed to write output: %s", err) return } } else { content := &Content{ Body: string(body), Nav: d.Navigation(), } if err := indexTemplate.Execute(w, content); err != nil { glog.Errorln("Failed to expand template:", err) } } } }
// ReportError formats an HTTP error response and also logs the detailed error message. func ReportError(w http.ResponseWriter, r *http.Request, err error, message string) { glog.Errorln(message, err) http.Error(w, fmt.Sprintf("%s %s", message, err), 500) }
// byBlameHandler returns a page with the digests to be triaged grouped by blamelist. func byBlameHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") if *local { loadTemplates() } tile, sum, err := allUntriagedSummaries() commits := tile.Commits if err != nil { util.ReportError(w, r, err, "Failed to load summaries.") return } // This is a very simple grouping of digests, for every digest we look up the // blame list for that digest and then use the concatenated git hashes as a // group id. All of the digests are then grouped by their group id. // Collects a ByBlame for each untriaged digest, keyed by group id. grouped := map[string][]*ByBlame{} // The Commit info for each group id. commitinfo := map[string][]*tiling.Commit{} // map [groupid] [test] TestRollup rollups := map[string]map[string]*TestRollup{} for test, s := range sum { for _, d := range s.UntHashes { dist := blamer.GetBlame(test, d, commits) groupid := strings.Join(lookUpCommits(dist.Freq, commits), ":") // Only fill in commitinfo for each groupid only once. if _, ok := commitinfo[groupid]; !ok { ci := []*tiling.Commit{} for _, index := range dist.Freq { ci = append(ci, commits[index]) } sort.Sort(CommitSlice(ci)) commitinfo[groupid] = ci } // Construct a ByBlame and add it to grouped. value := &ByBlame{ Test: test, Digest: d, Blame: dist, CommitIndices: dist.Freq, } if _, ok := grouped[groupid]; !ok { grouped[groupid] = []*ByBlame{value} } else { grouped[groupid] = append(grouped[groupid], value) } if _, ok := rollups[groupid]; !ok { rollups[groupid] = map[string]*TestRollup{} } // Calculate the rollups. if _, ok := rollups[groupid][test]; !ok { rollups[groupid][test] = &TestRollup{ Test: test, Num: 0, SampleDigest: d, } } rollups[groupid][test].Num += 1 } } // The Commit info needs to be accessed via Javascript, so serialize it into // JSON here. commitinfojs, err := json.MarshalIndent(commitinfo, "", " ") if err != nil { util.ReportError(w, r, err, "Failed to encode response data.") return } keys := []string{} for groupid, _ := range grouped { keys = append(keys, groupid) } sort.Strings(keys) if err := templates.ExecuteTemplate(w, "byblame.html", struct { Keys []string ByBlame map[string][]*ByBlame CommitsJS template.JS // map [groupid] [testname] TestRollups map[string]map[string]*TestRollup }{ Keys: keys, ByBlame: grouped, CommitsJS: template.JS(string(commitinfojs)), TestRollups: rollups, }); err != nil { glog.Errorln("Failed to expand template:", err) } }