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