@@ -1077,7 +1077,6 @@ func handleAdmin(c context.Context, w http.ResponseWriter, r *http.Request) erro
10771077}
10781078
10791079// handleBug serves page about a single bug (which is passed in id argument).
1080- // nolint: gocyclo
10811080func handleBug (c context.Context , w http.ResponseWriter , r * http.Request ) error {
10821081 bug , err := findBugByID (c , r )
10831082 if err != nil {
@@ -1094,11 +1093,67 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error
10941093 if err != nil {
10951094 return err
10961095 }
1096+ cfg := getNsConfig (c , hdr .Namespace )
10971097 bugDetails , err := loadBugDetails (c , bug , accessLevel )
10981098 if err != nil {
10991099 return err
11001100 }
1101- sections := []* uiCollapsible {}
1101+ crashesTable := & uiCrashTable {
1102+ Crashes : bugDetails .Crashes ,
1103+ Caption : fmt .Sprintf ("Crashes (%d)" , bugDetails .NumCrashes ),
1104+ }
1105+ sections , err := createBugSections (c , cfg , accessLevel , bug , bugDetails )
1106+ if err != nil {
1107+ return err
1108+ }
1109+ var aiWorkflows []string
1110+ var aiJobs []* uiAIJob
1111+ if hdr .AI {
1112+ aiWorkflows , err = aiBugWorkflows (c , bug )
1113+ if err != nil {
1114+ return err
1115+ }
1116+ jobs , err := aidb .LoadBugJobs (c , bug .keyHash (c ))
1117+ if err != nil {
1118+ return err
1119+ }
1120+ for _ , job := range jobs {
1121+ aiJobs = append (aiJobs , makeUIAIJob (job ))
1122+ }
1123+ }
1124+ data := & uiBugPage {
1125+ Header : hdr ,
1126+ Now : timeNow (c ),
1127+ Sections : sections ,
1128+ LabelGroups : getLabelGroups (c , bug ),
1129+ Crashes : crashesTable ,
1130+ Bug : bugDetails ,
1131+ AIWorkflows : aiWorkflows ,
1132+ AIJobs : aiJobs ,
1133+ }
1134+ if accessLevel == AccessAdmin && ! bug .hasUserSubsystems () {
1135+ data .DebugSubsystems = urlutil .SetParam (data .Bug .Link , "debug_subsystems" , "1" )
1136+ }
1137+ if workflow := r .FormValue ("ai-job-create" ); workflow != "" {
1138+ if ! hdr .AI {
1139+ return ErrAccess
1140+ }
1141+ if err := aiBugJobCreate (c , workflow , bug ); err != nil {
1142+ return err
1143+ }
1144+ hdr .Message = fmt .Sprintf ("AI workflow %v is created" , workflow )
1145+ }
1146+ if r .FormValue ("json" ) == "1" {
1147+ w .Header ().Set ("Content-Type" , "application/json" )
1148+ return writeJSONVersionOf (w , data )
1149+ }
1150+
1151+ return serveTemplate (w , "bug.html" , data )
1152+ }
1153+
1154+ func createBugSections (c context.Context , cfg * Config , accessLevel AccessLevel ,
1155+ bug * Bug , bugDetails * uiBugDetails ) ([]* uiCollapsible , error ) {
1156+ var sections []* uiCollapsible
11021157 if bugDetails .DupOf != nil {
11031158 sections = append (sections , & uiCollapsible {
11041159 Title : "Duplicate of" ,
@@ -1110,10 +1165,6 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error
11101165 },
11111166 })
11121167 }
1113- crashesTable := & uiCrashTable {
1114- Crashes : bugDetails .Crashes ,
1115- Caption : fmt .Sprintf ("Crashes (%d)" , bugDetails .NumCrashes ),
1116- }
11171168 if dups := bugDetails .Dups ; len (dups .Bugs ) > 0 {
11181169 sections = append (sections , & uiCollapsible {
11191170 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
11231174 }
11241175 discussions , err := getBugDiscussionsUI (c , bug )
11251176 if err != nil {
1126- return err
1177+ return nil , err
11271178 }
11281179 if len (discussions ) > 0 {
11291180 sections = append (sections , & uiCollapsible {
@@ -1135,7 +1186,7 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error
11351186 }
11361187 treeTestJobs , err := treeTestJobs (c , bug )
11371188 if err != nil {
1138- return err
1189+ return nil , err
11391190 }
11401191 if len (treeTestJobs ) > 0 {
11411192 sections = append (sections , & uiCollapsible {
@@ -1148,14 +1199,14 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error
11481199 if similar := bugDetails .Similar ; len (similar .Bugs ) > 0 {
11491200 sections = append (sections , & uiCollapsible {
11501201 Title : fmt .Sprintf ("Similar bugs (%d)" , len (similar .Bugs )),
1151- Show : getNsConfig ( c , hdr . Namespace ) .AccessLevel != AccessPublic ,
1202+ Show : cfg .AccessLevel != AccessPublic ,
11521203 Type : sectionBugList ,
11531204 Value : similar ,
11541205 })
11551206 }
11561207 testPatchJobs , err := loadTestPatchJobs (c , bug )
11571208 if err != nil {
1158- return err
1209+ return nil , err
11591210 }
11601211 if len (testPatchJobs ) > 0 {
11611212 sections = append (sections , & uiCollapsible {
@@ -1175,63 +1226,20 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error
11751226 Value : reproAttempts ,
11761227 })
11771228 }
1178- var aiWorkflows []string
1179- var aiJobs []* uiAIJob
1180- if hdr .AI {
1181- aiWorkflows , err = aiBugWorkflows (c , bug )
1182- if err != nil {
1183- return err
1184- }
1185- jobs , err := aidb .LoadBugJobs (c , bug .keyHash (c ))
1186- if err != nil {
1187- return err
1188- }
1189- for _ , job := range jobs {
1190- aiJobs = append (aiJobs , makeUIAIJob (job ))
1191- }
1192- }
1193- data := & uiBugPage {
1194- Header : hdr ,
1195- Now : timeNow (c ),
1196- Sections : sections ,
1197- LabelGroups : getLabelGroups (c , bug ),
1198- Crashes : crashesTable ,
1199- Bug : bugDetails ,
1200- AIWorkflows : aiWorkflows ,
1201- AIJobs : aiJobs ,
1202- }
1203- if accessLevel == AccessAdmin && ! bug .hasUserSubsystems () {
1204- data .DebugSubsystems = urlutil .SetParam (data .Bug .Link , "debug_subsystems" , "1" )
1205- }
12061229 // bug.BisectFix is set to BisectNot in three cases :
12071230 // - no fix bisections have been performed on the bug
12081231 // - fix bisection was performed but resulted in a crash on HEAD
12091232 // - there have been infrastructure problems during the job execution
12101233 if len (bugDetails .BisectFixJobs ) > 1 || len (bugDetails .BisectFixJobs ) > 0 && bugDetails .BisectFixJob == nil {
1211- data . Sections = append (data . Sections , makeCollapsibleBugJobs (
1234+ sections = append (sections , makeCollapsibleBugJobs (
12121235 "Fix bisection attempts" , bugDetails .BisectFixJobs ))
12131236 }
12141237 // Similarly, a cause bisection can be repeated if there were infrastructure problems.
12151238 if len (bugDetails .BisectCauseJobs ) > 1 || len (bugDetails .BisectCauseJobs ) > 0 && bugDetails .BisectCauseJob == nil {
1216- data . Sections = append (data . Sections , makeCollapsibleBugJobs (
1239+ sections = append (sections , makeCollapsibleBugJobs (
12171240 "Cause bisection attempts" , bugDetails .BisectCauseJobs ))
12181241 }
1219-
1220- if workflow := r .FormValue ("ai-job-create" ); workflow != "" {
1221- if ! hdr .AI {
1222- return ErrAccess
1223- }
1224- if err := aiBugJobCreate (c , workflow , bug ); err != nil {
1225- return err
1226- }
1227- hdr .Message = fmt .Sprintf ("AI workflow %v is created" , workflow )
1228- }
1229- if r .FormValue ("json" ) == "1" {
1230- w .Header ().Set ("Content-Type" , "application/json" )
1231- return writeJSONVersionOf (w , data )
1232- }
1233-
1234- return serveTemplate (w , "bug.html" , data )
1242+ return sections , nil
12351243}
12361244
12371245func loadBugDetails (c context.Context , bug * Bug , accessLevel AccessLevel ) (* uiBugDetails , error ) {
0 commit comments