diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2026-01-03 11:24:18 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2026-01-05 09:14:02 +0000 |
| commit | 917fe602eba8c93b32fb75c7093dabefefa101d6 (patch) | |
| tree | e5c1d7a36e3066c23bcb0e777c3ca2c1b04dd9fe | |
| parent | 77200b36494dbf8f7aa1500fbf5976585fffdb66 (diff) | |
dashboard/app: split handleBug function
Linter points it become too long.
| -rw-r--r-- | dashboard/app/main.go | 120 |
1 files changed, 64 insertions, 56 deletions
diff --git a/dashboard/app/main.go b/dashboard/app/main.go index c3ca24763..ef6738905 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -1077,7 +1077,6 @@ func handleAdmin(c context.Context, w http.ResponseWriter, r *http.Request) erro } // handleBug serves page about a single bug (which is passed in id argument). -// nolint: gocyclo func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error { bug, err := findBugByID(c, r) if err != nil { @@ -1094,11 +1093,67 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error if err != nil { return err } + cfg := getNsConfig(c, hdr.Namespace) bugDetails, err := loadBugDetails(c, bug, accessLevel) if err != nil { return err } - sections := []*uiCollapsible{} + crashesTable := &uiCrashTable{ + Crashes: bugDetails.Crashes, + Caption: fmt.Sprintf("Crashes (%d)", bugDetails.NumCrashes), + } + sections, err := createBugSections(c, cfg, accessLevel, bug, bugDetails) + if err != nil { + return err + } + var aiWorkflows []string + var aiJobs []*uiAIJob + if hdr.AI { + aiWorkflows, err = aiBugWorkflows(c, bug) + if err != nil { + return err + } + jobs, err := aidb.LoadBugJobs(c, bug.keyHash(c)) + if err != nil { + return err + } + for _, job := range jobs { + aiJobs = append(aiJobs, makeUIAIJob(job)) + } + } + data := &uiBugPage{ + Header: hdr, + Now: timeNow(c), + Sections: sections, + LabelGroups: getLabelGroups(c, bug), + Crashes: crashesTable, + Bug: bugDetails, + AIWorkflows: aiWorkflows, + AIJobs: aiJobs, + } + if accessLevel == AccessAdmin && !bug.hasUserSubsystems() { + data.DebugSubsystems = urlutil.SetParam(data.Bug.Link, "debug_subsystems", "1") + } + if workflow := r.FormValue("ai-job-create"); workflow != "" { + if !hdr.AI { + return ErrAccess + } + if err := aiBugJobCreate(c, workflow, bug); err != nil { + return err + } + hdr.Message = fmt.Sprintf("AI workflow %v is created", workflow) + } + if r.FormValue("json") == "1" { + w.Header().Set("Content-Type", "application/json") + return writeJSONVersionOf(w, data) + } + + return serveTemplate(w, "bug.html", data) +} + +func createBugSections(c context.Context, cfg *Config, accessLevel AccessLevel, + bug *Bug, bugDetails *uiBugDetails) ([]*uiCollapsible, error) { + var sections []*uiCollapsible if bugDetails.DupOf != nil { sections = append(sections, &uiCollapsible{ Title: "Duplicate of", @@ -1110,10 +1165,6 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error }, }) } - crashesTable := &uiCrashTable{ - Crashes: bugDetails.Crashes, - Caption: fmt.Sprintf("Crashes (%d)", bugDetails.NumCrashes), - } if dups := bugDetails.Dups; len(dups.Bugs) > 0 { sections = append(sections, &uiCollapsible{ Title: fmt.Sprintf("Duplicate bugs (%d)", len(dups.Bugs)), @@ -1123,7 +1174,7 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error } discussions, err := getBugDiscussionsUI(c, bug) if err != nil { - return err + return nil, err } if len(discussions) > 0 { sections = append(sections, &uiCollapsible{ @@ -1135,7 +1186,7 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error } treeTestJobs, err := treeTestJobs(c, bug) if err != nil { - return err + return nil, err } if len(treeTestJobs) > 0 { sections = append(sections, &uiCollapsible{ @@ -1148,14 +1199,14 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error if similar := bugDetails.Similar; len(similar.Bugs) > 0 { sections = append(sections, &uiCollapsible{ Title: fmt.Sprintf("Similar bugs (%d)", len(similar.Bugs)), - Show: getNsConfig(c, hdr.Namespace).AccessLevel != AccessPublic, + Show: cfg.AccessLevel != AccessPublic, Type: sectionBugList, Value: similar, }) } testPatchJobs, err := loadTestPatchJobs(c, bug) if err != nil { - return err + return nil, err } if len(testPatchJobs) > 0 { sections = append(sections, &uiCollapsible{ @@ -1175,63 +1226,20 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error Value: reproAttempts, }) } - var aiWorkflows []string - var aiJobs []*uiAIJob - if hdr.AI { - aiWorkflows, err = aiBugWorkflows(c, bug) - if err != nil { - return err - } - jobs, err := aidb.LoadBugJobs(c, bug.keyHash(c)) - if err != nil { - return err - } - for _, job := range jobs { - aiJobs = append(aiJobs, makeUIAIJob(job)) - } - } - data := &uiBugPage{ - Header: hdr, - Now: timeNow(c), - Sections: sections, - LabelGroups: getLabelGroups(c, bug), - Crashes: crashesTable, - Bug: bugDetails, - AIWorkflows: aiWorkflows, - AIJobs: aiJobs, - } - if accessLevel == AccessAdmin && !bug.hasUserSubsystems() { - data.DebugSubsystems = urlutil.SetParam(data.Bug.Link, "debug_subsystems", "1") - } // bug.BisectFix is set to BisectNot in three cases : // - no fix bisections have been performed on the bug // - fix bisection was performed but resulted in a crash on HEAD // - there have been infrastructure problems during the job execution if len(bugDetails.BisectFixJobs) > 1 || len(bugDetails.BisectFixJobs) > 0 && bugDetails.BisectFixJob == nil { - data.Sections = append(data.Sections, makeCollapsibleBugJobs( + sections = append(sections, makeCollapsibleBugJobs( "Fix bisection attempts", bugDetails.BisectFixJobs)) } // Similarly, a cause bisection can be repeated if there were infrastructure problems. if len(bugDetails.BisectCauseJobs) > 1 || len(bugDetails.BisectCauseJobs) > 0 && bugDetails.BisectCauseJob == nil { - data.Sections = append(data.Sections, makeCollapsibleBugJobs( + sections = append(sections, makeCollapsibleBugJobs( "Cause bisection attempts", bugDetails.BisectCauseJobs)) } - - if workflow := r.FormValue("ai-job-create"); workflow != "" { - if !hdr.AI { - return ErrAccess - } - if err := aiBugJobCreate(c, workflow, bug); err != nil { - return err - } - hdr.Message = fmt.Sprintf("AI workflow %v is created", workflow) - } - if r.FormValue("json") == "1" { - w.Header().Set("Content-Type", "application/json") - return writeJSONVersionOf(w, data) - } - - return serveTemplate(w, "bug.html", data) + return sections, nil } func loadBugDetails(c context.Context, bug *Bug, accessLevel AccessLevel) (*uiBugDetails, error) { |
