@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 91 lines 2.5 kB view raw
1<?php 2 3final class DifferentialUnitField 4 extends DifferentialCustomField { 5 6 public function getFieldKey() { 7 return 'differential:unit'; 8 } 9 10 public function getFieldName() { 11 return pht('Unit'); 12 } 13 14 public function getFieldDescription() { 15 return pht('Shows unit test results.'); 16 } 17 18 public function shouldAppearInPropertyView() { 19 return true; 20 } 21 22 public function renderPropertyViewValue(array $handles) { 23 return null; 24 } 25 26 public function shouldAppearInDiffPropertyView() { 27 return true; 28 } 29 30 public function renderDiffPropertyViewLabel(DifferentialDiff $diff) { 31 return $this->getFieldName(); 32 } 33 34 public function getWarningsForDetailView() { 35 $warnings = array(); 36 37 $viewer = $this->getViewer(); 38 $diff = $this->getObject()->getActiveDiff(); 39 40 $buildable = id(new HarbormasterBuildableQuery()) 41 ->setViewer($viewer) 42 ->withBuildablePHIDs(array($diff->getPHID())) 43 ->withManualBuildables(false) 44 ->executeOne(); 45 if ($buildable) { 46 switch ($buildable->getBuildableStatus()) { 47 case HarbormasterBuildableStatus::STATUS_BUILDING: 48 $warnings[] = pht( 49 'These changes have not finished building yet and may have build '. 50 'failures.'); 51 break; 52 case HarbormasterBuildableStatus::STATUS_FAILED: 53 $warnings[] = pht( 54 'These changes have failed to build.'); 55 break; 56 } 57 } 58 59 $status = $this->getObject()->getActiveDiff()->getUnitStatus(); 60 if ($status < DifferentialUnitStatus::UNIT_WARN) { 61 // Don't show any warnings. 62 } else if ($status == DifferentialUnitStatus::UNIT_AUTO_SKIP) { 63 // Don't show any warnings. 64 } else if ($status == DifferentialUnitStatus::UNIT_SKIP) { 65 $warnings[] = pht( 66 'Unit tests were skipped when generating these changes.'); 67 } else { 68 $warnings[] = pht('These changes have unit test problems.'); 69 } 70 71 return $warnings; 72 } 73 74 public function renderDiffPropertyViewValue(DifferentialDiff $diff) { 75 $status_value = $diff->getUnitStatus(); 76 $status = DifferentialUnitStatus::newStatusFromValue($status_value); 77 78 $status_icon = $status->getIconIcon(); 79 $status_color = $status->getIconColor(); 80 $status_name = $status->getName(); 81 82 $status = id(new PHUIStatusListView()) 83 ->addItem( 84 id(new PHUIStatusItemView()) 85 ->setIcon($status_icon, $status_color) 86 ->setTarget($status_name)); 87 88 return $status; 89 } 90 91}