|
4 | 4 |
|
5 | 5 | use App\Models\Build as EloquentBuild; |
6 | 6 | use App\Models\BuildGroup; |
7 | | -use App\Models\Comment; |
8 | 7 | use App\Models\Project; |
9 | 8 | use App\Models\UploadFile; |
10 | | -use App\Models\User; |
11 | 9 | use App\Utils\DatabaseCleanupUtils; |
12 | | -use App\Utils\PageTimer; |
13 | 10 | use App\Utils\RepositoryUtils; |
14 | | -use App\Utils\TestingDay; |
15 | 11 | use CDash\Database; |
16 | 12 | use CDash\Model\Build; |
17 | 13 | use CDash\Model\BuildGroupRule; |
@@ -185,378 +181,6 @@ public function coverage(int $build_id): View |
185 | 181 | ]); |
186 | 182 | } |
187 | 183 |
|
188 | | - public function apiBuildSummary(): JsonResponse |
189 | | - { |
190 | | - $pageTimer = new PageTimer(); |
191 | | - |
192 | | - $this->setBuildById((int) ($_GET['buildid'] ?? -1)); |
193 | | - |
194 | | - $date = TestingDay::get($this->project, $this->build->StartTime); |
195 | | - |
196 | | - $response = begin_JSON_response(); |
197 | | - $response['title'] = "{$this->project->Name} - Build Summary"; |
198 | | - |
199 | | - $previous_buildid = $this->build->GetPreviousBuildId(); |
200 | | - $current_buildid = $this->build->GetCurrentBuildId(); |
201 | | - $next_buildid = $this->build->GetNextBuildId(); |
202 | | - |
203 | | - $menu = []; |
204 | | - if ($this->build->GetParentId() > 0) { |
205 | | - $menu['back'] = 'index.php?project=' . urlencode($this->project->Name) . "&parentid={$this->build->GetParentId()}"; |
206 | | - } else { |
207 | | - $menu['back'] = 'index.php?project=' . urlencode($this->project->Name) . "&date=$date"; |
208 | | - } |
209 | | - |
210 | | - if ($previous_buildid > 0) { |
211 | | - $menu['previous'] = "/builds/$previous_buildid"; |
212 | | - |
213 | | - // Find the last submit date. |
214 | | - $previous_build = new Build(); |
215 | | - $previous_build->Id = $previous_buildid; |
216 | | - $previous_build->FillFromId($previous_build->Id); |
217 | | - $lastsubmitdate = date(FMT_DATETIMETZ, strtotime($previous_build->StartTime . ' UTC')); |
218 | | - } else { |
219 | | - $menu['previous'] = false; |
220 | | - $lastsubmitdate = 0; |
221 | | - } |
222 | | - |
223 | | - $menu['current'] = "/builds/$current_buildid"; |
224 | | - |
225 | | - if ($next_buildid > 0) { |
226 | | - $menu['next'] = "/builds/$next_buildid"; |
227 | | - } else { |
228 | | - $menu['next'] = false; |
229 | | - } |
230 | | - |
231 | | - $response['menu'] = $menu; |
232 | | - |
233 | | - get_dashboard_JSON($this->project->Name, $date, $response); |
234 | | - |
235 | | - // TODO: (williamjallen) verify if this block of code is still necessary |
236 | | - if (Auth::check()) { |
237 | | - /** @var User $user */ |
238 | | - $user = Auth::user(); |
239 | | - $response['user'] = [ |
240 | | - 'id' => $user->id, |
241 | | - 'admin' => $user->admin, |
242 | | - ]; |
243 | | - } |
244 | | - |
245 | | - // Notes added by users. |
246 | | - $eloquent_build = EloquentBuild::with(['comments', 'comments.user'])->findOrFail((int) $this->build->Id); |
247 | | - $notes_response = []; |
248 | | - /** |
249 | | - * @var Comment $comment |
250 | | - */ |
251 | | - foreach ($eloquent_build->comments()->with('user')->get() as $comment) { |
252 | | - $notes_response[] = [ |
253 | | - 'user' => $comment->user?->full_name, |
254 | | - 'date' => $comment->timestamp->toString(), |
255 | | - 'status' => match ($comment->status) { |
256 | | - Comment::STATUS_NORMAL => '[note]', |
257 | | - Comment::STATUS_FIX_IN_PROGRESS => '[fix in progress]', |
258 | | - Comment::STATUS_FIXED => '[fixed]', |
259 | | - default => '[unknown]', |
260 | | - }, |
261 | | - 'text' => $comment->text, |
262 | | - ]; |
263 | | - } |
264 | | - $response['notes'] = $notes_response; |
265 | | - |
266 | | - // Build |
267 | | - $build_response = []; |
268 | | - |
269 | | - $site_name = $this->build->GetSite()->name; |
270 | | - $build_response['site'] = $site_name; |
271 | | - $build_response['sitename_encoded'] = urlencode($site_name); |
272 | | - $build_response['siteid'] = $this->build->SiteId; |
273 | | - |
274 | | - $build_response['name'] = $this->build->Name; |
275 | | - $build_response['id'] = $this->build->Id; |
276 | | - $build_response['stamp'] = $this->build->GetStamp(); |
277 | | - $build_response['time'] = date(FMT_DATETIMETZ, strtotime($this->build->StartTime . ' UTC')); |
278 | | - $build_response['type'] = $this->build->Type; |
279 | | - |
280 | | - $build_response['note'] = EloquentBuild::findOrFail($this->build->Id)->notes()->count(); |
281 | | - |
282 | | - // Find the OS and compiler information |
283 | | - if ($this->build->GetParentId() > 0) { |
284 | | - $buildinfo = EloquentBuild::findOrNew($this->build->GetParentId()); |
285 | | - } else { |
286 | | - $buildinfo = EloquentBuild::findOrNew((int) $this->build->Id); |
287 | | - } |
288 | | - $build_response['osname'] = $buildinfo->osname; |
289 | | - $build_response['osplatform'] = $buildinfo->osplatform; |
290 | | - $build_response['osrelease'] = $buildinfo->osrelease; |
291 | | - $build_response['osversion'] = $buildinfo->osversion; |
292 | | - $build_response['compilername'] = $buildinfo->compilername; |
293 | | - $build_response['compilerversion'] = $buildinfo->compilerversion; |
294 | | - |
295 | | - $build_response['generator'] = $this->build->Generator; |
296 | | - $build_response['command'] = $this->build->Command; |
297 | | - $build_response['starttime'] = date(FMT_DATETIMETZ, strtotime($this->build->StartTime . ' UTC')); |
298 | | - $build_response['endtime'] = date(FMT_DATETIMETZ, strtotime($this->build->EndTime . ' UTC')); |
299 | | - |
300 | | - $build_response['lastsubmitbuild'] = $previous_buildid; |
301 | | - $build_response['lastsubmitdate'] = $lastsubmitdate; |
302 | | - |
303 | | - // Add labels to the response |
304 | | - $build_response['labels'] = $eloquent_build->labels()->pluck('text')->toArray(); |
305 | | - |
306 | | - $e_errors = $this->build->GetErrors(['type' => Build::TYPE_ERROR]); |
307 | | - $e_warnings = $this->build->GetErrors(['type' => Build::TYPE_WARN]); |
308 | | - |
309 | | - $f_errors = $this->build->GetFailures(['type' => Build::TYPE_ERROR]); |
310 | | - $f_warnings = $this->build->GetFailures(['type' => Build::TYPE_WARN]); |
311 | | - |
312 | | - $nerrors = count($e_errors) + count($f_errors); |
313 | | - $nwarnings = count($e_warnings) + count($f_warnings); |
314 | | - |
315 | | - $build_response['error'] = $nerrors; |
316 | | - |
317 | | - $build_response['nerrors'] = $nerrors; |
318 | | - $build_response['nwarnings'] = $nwarnings; |
319 | | - |
320 | | - // Display the build errors |
321 | | - |
322 | | - $errors_response = []; |
323 | | - |
324 | | - foreach ($e_errors as $error_array) { |
325 | | - $error_response = []; |
326 | | - $error_response['logline'] = $error_array['logline']; |
327 | | - $error_response['text'] = $error_array['stdoutput']; |
328 | | - $error_response['sourcefile'] = $error_array['sourcefile']; |
329 | | - $error_response['sourceline'] = $error_array['sourceline']; |
330 | | - $error_response['precontext'] = ''; |
331 | | - $error_response['postcontext'] = ''; |
332 | | - $errors_response[] = $error_response; |
333 | | - } |
334 | | - |
335 | | - // Display the build failure error |
336 | | - |
337 | | - foreach ($f_errors as $error_array) { |
338 | | - $error_response = []; |
339 | | - $error_response['sourcefile'] = $error_array['sourcefile']; |
340 | | - $error_response['stdoutput'] = $error_array['stdoutput']; |
341 | | - $error_response['stderror'] = $error_array['stderror']; |
342 | | - $errors_response[] = $error_response; |
343 | | - } |
344 | | - |
345 | | - $build_response['errors'] = $errors_response; |
346 | | - |
347 | | - // Display the warnings |
348 | | - $warnings_response = []; |
349 | | - |
350 | | - foreach ($e_warnings as $error_array) { |
351 | | - $warning_response = []; |
352 | | - $warning_response['logline'] = $error_array['logline']; |
353 | | - $warning_response['text'] = $error_array['stdoutput']; |
354 | | - $warning_response['sourcefile'] = $error_array['sourcefile']; |
355 | | - $warning_response['sourceline'] = $error_array['sourceline']; |
356 | | - $warning_response['precontext'] = ''; |
357 | | - $warning_response['postcontext'] = ''; |
358 | | - $warnings_response[] = $warning_response; |
359 | | - } |
360 | | - |
361 | | - // Display the build failure warnings |
362 | | - |
363 | | - foreach ($f_warnings as $error_array) { |
364 | | - $warning_response = []; |
365 | | - $warning_response['sourcefile'] = $error_array['sourcefile']; |
366 | | - $warning_response['stdoutput'] = $error_array['stdoutput']; |
367 | | - $warning_response['stderror'] = $error_array['stderror']; |
368 | | - $warnings_response[] = $warning_response; |
369 | | - } |
370 | | - |
371 | | - $build_response['warnings'] = $warnings_response; |
372 | | - $response['build'] = $build_response; |
373 | | - |
374 | | - // Update |
375 | | - $update_response = []; |
376 | | - $update_array = DB::select(' |
377 | | - SELECT * |
378 | | - FROM |
379 | | - buildupdate AS u, |
380 | | - build AS b |
381 | | - WHERE |
382 | | - b.updateid = u.id |
383 | | - AND b.id = ? |
384 | | - ', [$this->build->Id])[0] ?? []; |
385 | | - |
386 | | - // TODO: (williamjallen) Determine what $buildupdate was supposed to be. It is currently undefined. |
387 | | - if (isset($buildupdate)) { |
388 | | - // show the update only if we have one |
389 | | - $response['hasupdate'] = true; |
390 | | - // Checking for locally modify files |
391 | | - $nerrors = (int) DB::select(" |
392 | | - SELECT count(*) AS c |
393 | | - FROM |
394 | | - updatefile, |
395 | | - build |
396 | | - WHERE |
397 | | - updatefile.updateid=build.updateid |
398 | | - AND build.id = ? |
399 | | - AND author = 'Local User' |
400 | | - ", [$this->build->Id])[0]->c; |
401 | | - |
402 | | - // Check also if the status is not zero |
403 | | - if (strlen($update_array->status) > 0 && $update_array->status != '0') { |
404 | | - $nerrors++; |
405 | | - $update_response['status'] = $update_array->status; |
406 | | - } |
407 | | - $nwarnings = 0; |
408 | | - $update_response['nerrors'] = $nerrors; |
409 | | - $update_response['nwarnings'] = $nwarnings; |
410 | | - |
411 | | - $nupdates = (int) DB::select(' |
412 | | - SELECT count(*) AS c |
413 | | - FROM updatefile, build |
414 | | - WHERE updatefile.updateid=build.updateid AND build.id=? |
415 | | - ', [$this->build->Id])[0]->c; |
416 | | - $update_response['nupdates'] = $nupdates; |
417 | | - |
418 | | - $update_response['command'] = $update_array->command; |
419 | | - $update_response['type'] = $update_array->type; |
420 | | - $update_response['starttime'] = date(FMT_DATETIMETZ, strtotime($update_array->starttime . ' UTC')); |
421 | | - $update_response['endtime'] = date(FMT_DATETIMETZ, strtotime($update_array->endtime . ' UTC')); |
422 | | - } else { |
423 | | - $response['hasupdate'] = false; |
424 | | - $update_response['nerrors'] = 0; |
425 | | - $update_response['nwarnings'] = 0; |
426 | | - } |
427 | | - $response['update'] = $update_response; |
428 | | - |
429 | | - // Configure |
430 | | - $configure_response = []; |
431 | | - $configure_array = DB::select(' |
432 | | - SELECT * |
433 | | - FROM configure c |
434 | | - JOIN build2configure b2c ON b2c.configureid=c.id |
435 | | - WHERE b2c.buildid=? |
436 | | - ', [$this->build->Id])[0] ?? []; |
437 | | - if ($configure_array !== []) { |
438 | | - $response['hasconfigure'] = true; |
439 | | - $nerrors = 0; |
440 | | - if ($configure_array->status != 0) { |
441 | | - $nerrors = 1; |
442 | | - } |
443 | | - |
444 | | - $configure_response['nerrors'] = $nerrors; |
445 | | - $configure_response['nwarnings'] = $configure_array->warnings; |
446 | | - |
447 | | - $configure_response['status'] = $configure_array->status; |
448 | | - $configure_response['command'] = $configure_array->command; |
449 | | - $configure_response['output'] = $configure_array->log; |
450 | | - $configure_response['starttime'] = date(FMT_DATETIMETZ, strtotime($configure_array->starttime . ' UTC')); |
451 | | - $configure_response['endtime'] = date(FMT_DATETIMETZ, strtotime($configure_array->endtime . ' UTC')); |
452 | | - $response['configure'] = $configure_response; |
453 | | - } else { |
454 | | - $response['hasconfigure'] = false; |
455 | | - } |
456 | | - |
457 | | - // Test |
458 | | - $test_response = []; |
459 | | - $nerrors = 0; |
460 | | - $nwarnings = 0; |
461 | | - $test_response['nerrors'] = $nerrors; |
462 | | - $test_response['nwarnings'] = $nwarnings; |
463 | | - |
464 | | - $test_response['npassed'] = (int) DB::select(" |
465 | | - SELECT count(1) AS c |
466 | | - FROM build2test |
467 | | - WHERE buildid=? AND status='passed' |
468 | | - ", [$this->build->Id])[0]->c; |
469 | | - |
470 | | - $test_response['nnotrun'] = (int) DB::select(" |
471 | | - SELECT count(1) AS c |
472 | | - FROM build2test |
473 | | - WHERE buildid=? AND status='notrun' |
474 | | - ", [$this->build->Id])[0]->c; |
475 | | - |
476 | | - $test_response['nfailed'] = (int) DB::select(" |
477 | | - SELECT count(1) AS c |
478 | | - FROM build2test |
479 | | - WHERE buildid=? AND status='failed' |
480 | | - ", [$this->build->Id])[0]->c; |
481 | | - |
482 | | - $response['test'] = $test_response; |
483 | | - |
484 | | - // Coverage |
485 | | - $response['hascoverage'] = false; |
486 | | - $coverage_array = DB::select('SELECT * FROM coveragesummary WHERE buildid=?', [$this->build->Id])[0] ?? []; |
487 | | - if ($coverage_array !== []) { |
488 | | - $total_lines = (int) $coverage_array->loctested + (int) $coverage_array->locuntested; |
489 | | - |
490 | | - $coverage_percent = $total_lines > 0 ? round(($coverage_array->loctested / $total_lines) * 100, 2) : 0; |
491 | | - $response['coverage'] = $coverage_percent; |
492 | | - $response['hascoverage'] = true; |
493 | | - } |
494 | | - |
495 | | - // Previous build |
496 | | - if ($previous_buildid > 0 && isset($previous_build)) { |
497 | | - $previous_build_update = EloquentBuild::findOrFail($previous_buildid)->updateStep; |
498 | | - |
499 | | - $response['previousbuild'] = [ |
500 | | - 'buildid' => $previous_buildid, |
501 | | - // Update |
502 | | - 'nupdateerrors' => $previous_build_update->errors ?? 0, |
503 | | - 'nupdatewarnings' => $previous_build_update->warnings ?? 0, |
504 | | - // Configure |
505 | | - 'nconfigureerrors' => $previous_build->GetNumberOfConfigureErrors(), |
506 | | - 'nconfigurewarnings' => $previous_build->GetNumberOfConfigureWarnings(), |
507 | | - // Build |
508 | | - 'nerrors' => $previous_build->GetNumberOfErrors(), |
509 | | - 'nwarnings' => $previous_build->GetNumberOfWarnings(), |
510 | | - // Test |
511 | | - 'ntestfailed' => $previous_build->GetNumberOfFailedTests(), |
512 | | - 'ntestnotrun' => $previous_build->GetNumberOfNotRunTests(), |
513 | | - ]; |
514 | | - } |
515 | | - |
516 | | - // Next build |
517 | | - if ($next_buildid > 0) { |
518 | | - $next_build = new Build(); |
519 | | - $next_build->Id = $next_buildid; |
520 | | - $next_build->FillFromId($next_build->Id); |
521 | | - $next_build_update = EloquentBuild::findOrFail($next_buildid)->updateStep; |
522 | | - |
523 | | - $response['nextbuild'] = [ |
524 | | - 'buildid' => $next_buildid, |
525 | | - // Update |
526 | | - 'nupdateerrors' => $next_build_update->errors ?? 0, |
527 | | - 'nupdatewarnings' => $next_build_update->warnings ?? 0, |
528 | | - // Configure |
529 | | - 'nconfigureerrors' => $next_build->GetNumberOfConfigureErrors(), |
530 | | - 'nconfigurewarnings' => $next_build->GetNumberOfConfigureWarnings(), |
531 | | - // Build |
532 | | - 'nerrors' => $next_build->GetNumberOfErrors(), |
533 | | - 'nwarnings' => $next_build->GetNumberOfWarnings(), |
534 | | - // Test |
535 | | - 'ntestfailed' => $next_build->GetNumberOfFailedTests(), |
536 | | - 'ntestnotrun' => $next_build->GetNumberOfNotRunTests(), |
537 | | - ]; |
538 | | - } |
539 | | - |
540 | | - // Check if this project uses a supported bug tracker. |
541 | | - $generate_issue_link = false; |
542 | | - $new_issue_url = ''; |
543 | | - switch ($this->project->BugTrackerType) { |
544 | | - case 'Buganizer': |
545 | | - case 'JIRA': |
546 | | - case 'GitHub': |
547 | | - $generate_issue_link = true; |
548 | | - break; |
549 | | - } |
550 | | - if ($generate_issue_link) { |
551 | | - $new_issue_url = RepositoryUtils::generate_bugtracker_new_issue_link($this->build, $this->project); |
552 | | - $response['bugtracker'] = $this->project->BugTrackerType; |
553 | | - } |
554 | | - $response['newissueurl'] = $new_issue_url; |
555 | | - |
556 | | - $pageTimer->end($response); |
557 | | - return response()->json(cast_data_for_JSON($response)); |
558 | | - } |
559 | | - |
560 | 184 | public function files(int $build_id): View |
561 | 185 | { |
562 | 186 | $this->setBuildById($build_id); |
|
0 commit comments