Differential D11692 Diff 28134 src/applications/harbormaster/controller/HarbormasterBuildViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/controller/HarbormasterBuildViewController.php
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | foreach ($build_targets as $build_target) { | ||||
} | } | ||||
$properties = new PHUIPropertyListView(); | $properties = new PHUIPropertyListView(); | ||||
$properties->addProperty('Build Target ID', $build_target->getID()); | $properties->addProperty('Build Target ID', $build_target->getID()); | ||||
$target_box->addPropertyList($properties, pht('Metadata')); | $target_box->addPropertyList($properties, pht('Metadata')); | ||||
$targets[] = $target_box; | $targets[] = $target_box; | ||||
$targets[] = $this->buildUnitItems($build, $build_target); | |||||
$targets[] = $this->buildLog($build, $build_target); | $targets[] = $this->buildLog($build, $build_target); | ||||
} | } | ||||
$timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
$build, | $build, | ||||
new HarbormasterBuildTransactionQuery()); | new HarbormasterBuildTransactionQuery()); | ||||
$timeline->setShouldTerminate(true); | $timeline->setShouldTerminate(true); | ||||
Show All 32 Lines | foreach ($artifacts as $artifact) { | ||||
if ($item !== null) { | if ($item !== null) { | ||||
$list->addItem($item); | $list->addItem($item); | ||||
} | } | ||||
} | } | ||||
return $list; | return $list; | ||||
} | } | ||||
private function buildUnitItems( | |||||
HarbormasterBuild $build, | |||||
HarbormasterBuildTarget $build_target) { | |||||
$request = $this->getRequest(); | |||||
$viewer = $request->getUser(); | |||||
$items = id(new HarbormasterBuildItemQuery()) | |||||
->setViewer($viewer) | |||||
->withTypes(array(HarbormasterBuildItem::TYPE_UNIT)) | |||||
->withBuildTargetPHIDs(array($build_target->getPHID())) | |||||
->execute(); | |||||
if (count($items) === 0) { | |||||
return null; | |||||
} | |||||
$rows = array(); | |||||
$this->requireResource('differential-core-view-css'); | |||||
$this->requireResource('differential-revision-history-css'); | |||||
$show_limit = 10; | |||||
$hidden = array(); | |||||
$totals = array(); | |||||
$udata = mpull($items, 'getDetails'); | |||||
if ($udata) { | |||||
$sort_map = array( | |||||
ArcanistUnitTestResult::RESULT_BROKEN => 0, | |||||
ArcanistUnitTestResult::RESULT_FAIL => 1, | |||||
ArcanistUnitTestResult::RESULT_UNSOUND => 2, | |||||
ArcanistUnitTestResult::RESULT_SKIP => 3, | |||||
ArcanistUnitTestResult::RESULT_POSTPONED => 4, | |||||
ArcanistUnitTestResult::RESULT_PASS => 5, | |||||
); | |||||
foreach ($udata as $key => $test) { | |||||
$udata[$key]['sort'] = idx($sort_map, idx($test, 'result')); | |||||
} | |||||
$udata = isort($udata, 'sort'); | |||||
$engine = new PhabricatorMarkupEngine(); | |||||
$engine->setViewer($this->getViewer()); | |||||
$markup_objects = array(); | |||||
foreach ($udata as $key => $test) { | |||||
$userdata = idx($test, 'userData'); | |||||
if ($userdata) { | |||||
if ($userdata !== false) { | |||||
$userdata = str_replace("\000", '', $userdata); | |||||
} | |||||
$markup_object = id(new PhabricatorMarkupOneOff()) | |||||
->setContent($userdata) | |||||
->setPreserveLinebreaks(true); | |||||
$engine->addObject($markup_object, 'default'); | |||||
$markup_objects[$key] = $markup_object; | |||||
} | |||||
} | |||||
$engine->process(); | |||||
foreach ($udata as $key => $test) { | |||||
$result = idx($test, 'result'); | |||||
$default_hide = false; | |||||
switch ($result) { | |||||
case ArcanistUnitTestResult::RESULT_POSTPONED: | |||||
$default_hide = true; | |||||
break; | |||||
} | |||||
if ($show_limit && !$default_hide) { | |||||
--$show_limit; | |||||
$show = true; | |||||
} else { | |||||
$show = false; | |||||
if (empty($hidden[$result])) { | |||||
$hidden[$result] = 0; | |||||
} | |||||
$hidden[$result]++; | |||||
} | |||||
if (empty($totals[$result])) { | |||||
$totals[$result] = 0; | |||||
} | |||||
$totals[$result]++; | |||||
if (empty($totals['total'])) { | |||||
$totals['total'] = 0; | |||||
} | |||||
$totals['total']++; | |||||
$value = idx($test, 'name'); | |||||
$namespace = idx($test, 'namespace'); | |||||
if ($namespace) { | |||||
$value = $namespace.'::'.$value; | |||||
} | |||||
if (!empty($test['link'])) { | |||||
$value = phutil_tag( | |||||
'a', | |||||
array( | |||||
'href' => $test['link'], | |||||
'target' => '_blank', | |||||
), | |||||
$value); | |||||
} | |||||
$rows[] = array( | |||||
'style' => $this->getUnitResultStyle($result), | |||||
'name' => ucwords($result), | |||||
'value' => $value, | |||||
'show' => $show, | |||||
); | |||||
if (isset($markup_objects[$key])) { | |||||
$rows[] = array( | |||||
'style' => 'details', | |||||
'value' => $engine->getOutput($markup_objects[$key], 'default'), | |||||
'show' => false, | |||||
); | |||||
if (empty($hidden['details'])) { | |||||
$hidden['details'] = 0; | |||||
} | |||||
$hidden['details']++; | |||||
} | |||||
} | |||||
} | |||||
$show_string = $this->renderUnitShowString($hidden); | |||||
$view = new DifferentialResultsTableView(); | |||||
$view->setRows($rows); | |||||
$view->setShowMoreString($show_string); | |||||
$header = id(new PHUIHeaderView()) | |||||
->setHeader(pht('Test Results')) | |||||
->setSubheader($this->getUnitSummary($totals)) | |||||
->setUser($viewer); | |||||
$box = id(new PHUIObjectBoxView()) | |||||
->setHeader($header) | |||||
->setForm($view); | |||||
return $box; | |||||
} | |||||
private function getUnitResultStyle($result) { | |||||
$map = array( | |||||
ArcanistUnitTestResult::RESULT_PASS => 'green', | |||||
ArcanistUnitTestResult::RESULT_FAIL => 'red', | |||||
ArcanistUnitTestResult::RESULT_SKIP => 'blue', | |||||
ArcanistUnitTestResult::RESULT_BROKEN => 'red', | |||||
ArcanistUnitTestResult::RESULT_UNSOUND => 'yellow', | |||||
ArcanistUnitTestResult::RESULT_POSTPONED => 'blue', | |||||
); | |||||
return idx($map, $result); | |||||
} | |||||
private function getUnitSummary(array $hidden) { | |||||
// Reorder hidden things by severity. | |||||
$hidden = array_select_keys( | |||||
$hidden, | |||||
array( | |||||
ArcanistUnitTestResult::RESULT_BROKEN, | |||||
ArcanistUnitTestResult::RESULT_FAIL, | |||||
ArcanistUnitTestResult::RESULT_UNSOUND, | |||||
ArcanistUnitTestResult::RESULT_SKIP, | |||||
ArcanistUnitTestResult::RESULT_POSTPONED, | |||||
ArcanistUnitTestResult::RESULT_PASS, | |||||
'details', | |||||
'total', | |||||
)) + $hidden; | |||||
$noun = array( | |||||
ArcanistUnitTestResult::RESULT_BROKEN => 'Broken', | |||||
ArcanistUnitTestResult::RESULT_FAIL => 'Failed', | |||||
ArcanistUnitTestResult::RESULT_UNSOUND => 'Unsound', | |||||
ArcanistUnitTestResult::RESULT_SKIP => 'Skipped', | |||||
ArcanistUnitTestResult::RESULT_POSTPONED => 'Postponed', | |||||
ArcanistUnitTestResult::RESULT_PASS => 'Passed', | |||||
); | |||||
$show = array(); | |||||
foreach ($hidden as $key => $value) { | |||||
if ($key == 'details') { | |||||
$show[] = pht('%d Detail(s)', $value); | |||||
} else if ($key == 'total') { | |||||
$show[] = pht('%d Total', $value); | |||||
} else { | |||||
$show[] = $value.' '.idx($noun, $key); | |||||
} | |||||
} | |||||
return implode(', ', $show); | |||||
} | |||||
private function renderUnitShowString(array $hidden) { | |||||
if (!$hidden) { | |||||
return null; | |||||
} | |||||
$summary = $this->getUnitSummary($hidden); | |||||
return 'Show Full Unit Results ('.$summary.')'; | |||||
} | |||||
private function buildLog( | private function buildLog( | ||||
HarbormasterBuild $build, | HarbormasterBuild $build, | ||||
HarbormasterBuildTarget $build_target) { | HarbormasterBuildTarget $build_target) { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
$limit = $request->getInt('l', 25); | $limit = $request->getInt('l', 25); | ||||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |