Differential D19615 Diff 46892 src/applications/harbormaster/storage/build/HarbormasterBuildUnitMessage.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/storage/build/HarbormasterBuildUnitMessage.php
| <?php | <?php | ||||
| final class HarbormasterBuildUnitMessage | final class HarbormasterBuildUnitMessage | ||||
| extends HarbormasterDAO { | extends HarbormasterDAO { | ||||
| protected $buildTargetPHID; | protected $buildTargetPHID; | ||||
| protected $engine; | protected $engine; | ||||
| protected $namespace; | protected $namespace; | ||||
| protected $name; | protected $name; | ||||
| protected $result; | protected $result; | ||||
| protected $duration; | protected $duration; | ||||
| protected $properties = array(); | protected $properties = array(); | ||||
| private $buildTarget = self::ATTACHABLE; | private $buildTarget = self::ATTACHABLE; | ||||
| const FORMAT_TEXT = 'text'; | |||||
| const FORMAT_REMARKUP = 'remarkup'; | |||||
| public static function initializeNewUnitMessage( | public static function initializeNewUnitMessage( | ||||
| HarbormasterBuildTarget $build_target) { | HarbormasterBuildTarget $build_target) { | ||||
| return id(new HarbormasterBuildUnitMessage()) | return id(new HarbormasterBuildUnitMessage()) | ||||
| ->setBuildTargetPHID($build_target->getPHID()); | ->setBuildTargetPHID($build_target->getPHID()); | ||||
| } | } | ||||
| public static function getParameterSpec() { | public static function getParameterSpec() { | ||||
| return array( | return array( | ||||
| Show All 37 Lines | return array( | ||||
| 'description' => pht( | 'description' => pht( | ||||
| 'Coverage information for this test.'), | 'Coverage information for this test.'), | ||||
| ), | ), | ||||
| 'details' => array( | 'details' => array( | ||||
| 'type' => 'optional string', | 'type' => 'optional string', | ||||
| 'description' => pht( | 'description' => pht( | ||||
| 'Additional human-readable information about the failure.'), | 'Additional human-readable information about the failure.'), | ||||
| ), | ), | ||||
| 'format' => array( | |||||
| 'type' => 'optional string', | |||||
| 'description' => pht( | |||||
| 'Format for the text provided in "details". Valid values are '. | |||||
| '"text" (default) or "remarkup". This controls how test details '. | |||||
| 'are rendered when shown to users.'), | |||||
| ), | |||||
| ); | ); | ||||
| } | } | ||||
| public static function newFromDictionary( | public static function newFromDictionary( | ||||
| HarbormasterBuildTarget $build_target, | HarbormasterBuildTarget $build_target, | ||||
| array $dict) { | array $dict) { | ||||
| $obj = self::initializeNewUnitMessage($build_target); | $obj = self::initializeNewUnitMessage($build_target); | ||||
| Show All 22 Lines | if ($coverage) { | ||||
| $obj->setProperty('coverage', $coverage); | $obj->setProperty('coverage', $coverage); | ||||
| } | } | ||||
| $details = idx($dict, 'details'); | $details = idx($dict, 'details'); | ||||
| if ($details) { | if ($details) { | ||||
| $obj->setProperty('details', $details); | $obj->setProperty('details', $details); | ||||
| } | } | ||||
| $format = idx($dict, 'format'); | |||||
| if ($format) { | |||||
| $obj->setProperty('format', $format); | |||||
| } | |||||
| return $obj; | return $obj; | ||||
| } | } | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
| 'properties' => self::SERIALIZATION_JSON, | 'properties' => self::SERIALIZATION_JSON, | ||||
| ), | ), | ||||
| Show All 29 Lines | public function setProperty($key, $value) { | ||||
| $this->properties[$key] = $value; | $this->properties[$key] = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getUnitMessageDetails() { | public function getUnitMessageDetails() { | ||||
| return $this->getProperty('details', ''); | return $this->getProperty('details', ''); | ||||
| } | } | ||||
| public function getUnitMessageDetailsFormat() { | |||||
| return $this->getProperty('format', self::FORMAT_TEXT); | |||||
| } | |||||
| public function newUnitMessageDetailsView( | |||||
| PhabricatorUser $viewer, | |||||
| $summarize = false) { | |||||
| $format = $this->getUnitMessageDetailsFormat(); | |||||
| $is_text = ($format !== self::FORMAT_REMARKUP); | |||||
| $is_remarkup = ($format === self::FORMAT_REMARKUP); | |||||
| $full_details = $this->getUnitMessageDetails(); | |||||
| if (!strlen($full_details)) { | |||||
| if ($summarize) { | |||||
| return null; | |||||
| } | |||||
| $details = phutil_tag('em', array(), pht('No details provided.')); | |||||
| } else if ($summarize) { | |||||
| if ($is_text) { | |||||
| $details = id(new PhutilUTF8StringTruncator()) | |||||
| ->setMaximumBytes(2048) | |||||
| ->truncateString($full_details); | |||||
| $details = phutil_split_lines($details); | |||||
| $limit = 3; | |||||
| if (count($details) > $limit) { | |||||
| $details = array_slice($details, 0, $limit); | |||||
| } | |||||
| $details = implode('', $details); | |||||
| } else { | |||||
| $details = $full_details; | |||||
| } | |||||
| } else { | |||||
| $details = $full_details; | |||||
| } | |||||
| require_celerity_resource('harbormaster-css'); | |||||
| $classes = array(); | |||||
| $classes[] = 'harbormaster-unit-details'; | |||||
| if ($is_remarkup) { | |||||
| $details = new PHUIRemarkupView($viewer, $details); | |||||
| } else { | |||||
| $classes[] = 'harbormaster-unit-details-text'; | |||||
| $classes[] = 'PhabricatorMonospaced'; | |||||
| } | |||||
| return phutil_tag( | |||||
| 'div', | |||||
| array( | |||||
| 'class' => implode(' ', $classes), | |||||
| ), | |||||
| $details); | |||||
| } | |||||
| public function getUnitMessageDisplayName() { | public function getUnitMessageDisplayName() { | ||||
| $name = $this->getName(); | $name = $this->getName(); | ||||
| $namespace = $this->getNamespace(); | $namespace = $this->getNamespace(); | ||||
| if (strlen($namespace)) { | if (strlen($namespace)) { | ||||
| $name = $namespace.'::'.$name; | $name = $namespace.'::'.$name; | ||||
| } | } | ||||
| Show All 28 Lines | |||||