@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make Harbormaster buildable status more of a nice flexible map and less of a bunch of switch statements

Summary: Depends on D19063. Ref T13054. Prepare for the addition of a new `PREPARING` status by getting rid of the "scattered mess of switch statements" pattern of status management.

Test Plan: Searched/browsed buildables. Viewed buildables. Viewed revisions. Grepped for all affected symbols.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13054

Differential Revision: https://secure.phabricator.com/D19064

+133 -89
+2
src/__phutil_library_map__.php
··· 1272 1272 'HarbormasterBuildablePHIDType' => 'applications/harbormaster/phid/HarbormasterBuildablePHIDType.php', 1273 1273 'HarbormasterBuildableQuery' => 'applications/harbormaster/query/HarbormasterBuildableQuery.php', 1274 1274 'HarbormasterBuildableSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildableSearchEngine.php', 1275 + 'HarbormasterBuildableStatus' => 'applications/harbormaster/constants/HarbormasterBuildableStatus.php', 1275 1276 'HarbormasterBuildableTransaction' => 'applications/harbormaster/storage/HarbormasterBuildableTransaction.php', 1276 1277 'HarbormasterBuildableTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php', 1277 1278 'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php', ··· 6549 6550 'HarbormasterBuildablePHIDType' => 'PhabricatorPHIDType', 6550 6551 'HarbormasterBuildableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6551 6552 'HarbormasterBuildableSearchEngine' => 'PhabricatorApplicationSearchEngine', 6553 + 'HarbormasterBuildableStatus' => 'Phobject', 6552 6554 'HarbormasterBuildableTransaction' => 'PhabricatorApplicationTransaction', 6553 6555 'HarbormasterBuildableTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 6554 6556 'HarbormasterBuildableTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+2 -2
src/applications/differential/customfield/DifferentialUnitField.php
··· 44 44 ->executeOne(); 45 45 if ($buildable) { 46 46 switch ($buildable->getBuildableStatus()) { 47 - case HarbormasterBuildable::STATUS_BUILDING: 47 + case HarbormasterBuildableStatus::STATUS_BUILDING: 48 48 $warnings[] = pht( 49 49 'These changes have not finished building yet and may have build '. 50 50 'failures.'); 51 51 break; 52 - case HarbormasterBuildable::STATUS_FAILED: 52 + case HarbormasterBuildableStatus::STATUS_FAILED: 53 53 $warnings[] = pht( 54 54 'These changes have failed to build.'); 55 55 break;
+3 -4
src/applications/diffusion/view/DiffusionView.php
··· 205 205 final protected function renderBuildable( 206 206 HarbormasterBuildable $buildable, 207 207 $type = null) { 208 - $status = $buildable->getBuildableStatus(); 209 208 Javelin::initBehavior('phabricator-tooltips'); 210 209 211 - $icon = HarbormasterBuildable::getBuildableStatusIcon($status); 212 - $color = HarbormasterBuildable::getBuildableStatusColor($status); 213 - $name = HarbormasterBuildable::getBuildableStatusName($status); 210 + $icon = $buildable->getStatusIcon(); 211 + $color = $buildable->getStatusColor(); 212 + $name = $buildable->getStatusDisplayName(); 214 213 215 214 if ($type == 'button') { 216 215 return id(new PHUIButtonView())
+1 -1
src/applications/harbormaster/conduit/HarbormasterQueryBuildablesConduitAPIMethod.php
··· 65 65 $monogram = $buildable->getMonogram(); 66 66 67 67 $status = $buildable->getBuildableStatus(); 68 - $status_name = HarbormasterBuildable::getBuildableStatusName($status); 68 + $status_name = $buildable->getStatusDisplayName(); 69 69 70 70 $data[] = array( 71 71 'id' => $buildable->getID(),
+82
src/applications/harbormaster/constants/HarbormasterBuildableStatus.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildableStatus extends Phobject { 4 + 5 + const STATUS_BUILDING = 'building'; 6 + const STATUS_PASSED = 'passed'; 7 + const STATUS_FAILED = 'failed'; 8 + 9 + private $key; 10 + private $properties; 11 + 12 + public function __construct($key, array $properties) { 13 + $this->key = $key; 14 + $this->properties = $properties; 15 + } 16 + 17 + public static function newBuildableStatusObject($status) { 18 + $spec = self::getSpecification($status); 19 + return new self($status, $spec); 20 + } 21 + 22 + private function getProperty($key) { 23 + if (!array_key_exists($key, $this->properties)) { 24 + throw new Exception( 25 + pht( 26 + 'Attempting to access unknown buildable status property ("%s").', 27 + $key)); 28 + } 29 + 30 + return $this->properties[$key]; 31 + } 32 + 33 + public function getIcon() { 34 + return $this->getProperty('icon'); 35 + } 36 + 37 + public function getDisplayName() { 38 + return $this->getProperty('name'); 39 + } 40 + 41 + public function getColor() { 42 + return $this->getProperty('color'); 43 + } 44 + 45 + public static function getOptionMap() { 46 + return ipull(self::getSpecifications(), 'name'); 47 + } 48 + 49 + private static function getSpecifications() { 50 + return array( 51 + self::STATUS_BUILDING => array( 52 + 'name' => pht('Building'), 53 + 'color' => 'blue', 54 + 'icon' => 'fa-chevron-circle-right', 55 + ), 56 + self::STATUS_PASSED => array( 57 + 'name' => pht('Passed'), 58 + 'color' => 'green', 59 + 'icon' => 'fa-check-circle', 60 + ), 61 + self::STATUS_FAILED => array( 62 + 'name' => pht('Failed'), 63 + 'color' => 'red', 64 + 'icon' => 'fa-times-circle', 65 + ), 66 + ); 67 + } 68 + 69 + private static function getSpecification($status) { 70 + $map = self::getSpecifications(); 71 + if (isset($map[$status])) { 72 + return $map[$status]; 73 + } 74 + 75 + return array( 76 + 'name' => pht('Unknown ("%s")', $status), 77 + 'icon' => 'fa-question-circle', 78 + 'color' => 'bluegrey', 79 + ); 80 + } 81 + 82 + }
+7 -6
src/applications/harbormaster/engine/HarbormasterBuildEngine.php
··· 453 453 } 454 454 455 455 if ($any_fail) { 456 - $new_status = HarbormasterBuildable::STATUS_FAILED; 456 + $new_status = HarbormasterBuildableStatus::STATUS_FAILED; 457 457 } else if ($all_pass) { 458 - $new_status = HarbormasterBuildable::STATUS_PASSED; 458 + $new_status = HarbormasterBuildableStatus::STATUS_PASSED; 459 459 } else { 460 - $new_status = HarbormasterBuildable::STATUS_BUILDING; 460 + $new_status = HarbormasterBuildableStatus::STATUS_BUILDING; 461 461 } 462 462 463 463 $old_status = $buildable->getBuildableStatus(); ··· 477 477 // can look at the results themselves, and other users generally don't 478 478 // care about the outcome. 479 479 480 - $should_publish = $did_update && 481 - $new_status != HarbormasterBuildable::STATUS_BUILDING && 482 - !$buildable->getIsManualBuildable(); 480 + $should_publish = 481 + ($did_update) && 482 + ($new_status != HarbormasterBuildableStatus::STATUS_BUILDING) && 483 + (!$buildable->getIsManualBuildable()); 483 484 484 485 if (!$should_publish) { 485 486 return;
+3 -7
src/applications/harbormaster/event/HarbormasterUIEventListener.php
··· 87 87 88 88 $status_view = new PHUIStatusListView(); 89 89 90 - $buildable_status = $buildable->getBuildableStatus(); 91 - $buildable_icon = HarbormasterBuildable::getBuildableStatusIcon( 92 - $buildable_status); 93 - $buildable_color = HarbormasterBuildable::getBuildableStatusColor( 94 - $buildable_status); 95 - $buildable_name = HarbormasterBuildable::getBuildableStatusName( 96 - $buildable_status); 90 + $buildable_icon = $buildable->getStatusIcon(); 91 + $buildable_color = $buildable->getStatusColor(); 92 + $buildable_name = $buildable->getStatusDisplayName(); 97 93 98 94 $target = phutil_tag( 99 95 'a',
+4 -6
src/applications/harbormaster/query/HarbormasterBuildableSearchEngine.php
··· 33 33 id(new PhabricatorSearchCheckboxesField()) 34 34 ->setKey('statuses') 35 35 ->setLabel(pht('Statuses')) 36 - ->setOptions(HarbormasterBuildable::getBuildStatusMap()) 36 + ->setOptions(HarbormasterBuildableStatus::getOptionMap()) 37 37 ->setDescription(pht('Search for builds by buildable status.')), 38 38 id(new PhabricatorSearchThreeStateField()) 39 39 ->setLabel(pht('Manual')) ··· 169 169 $item->addIcon('fa-wrench grey', pht('Manual')); 170 170 } 171 171 172 - $status = $buildable->getBuildableStatus(); 173 - 174 - $status_icon = HarbormasterBuildable::getBuildableStatusIcon($status); 175 - $status_color = HarbormasterBuildable::getBuildableStatusColor($status); 176 - $status_label = HarbormasterBuildable::getBuildableStatusName($status); 172 + $status_icon = $buildable->getStatusIcon(); 173 + $status_color = $buildable->getStatusColor(); 174 + $status_label = $buildable->getStatusDisplayName(); 177 175 178 176 $item->setStatusIcon("{$status_icon} {$status_color}", $status_label); 179 177
+22 -56
src/applications/harbormaster/storage/HarbormasterBuildable.php
··· 15 15 private $containerObject = self::ATTACHABLE; 16 16 private $builds = self::ATTACHABLE; 17 17 18 - const STATUS_BUILDING = 'building'; 19 - const STATUS_PASSED = 'passed'; 20 - const STATUS_FAILED = 'failed'; 21 - 22 - public static function getBuildableStatusName($status) { 23 - $map = self::getBuildStatusMap(); 24 - return idx($map, $status, pht('Unknown ("%s")', $status)); 25 - } 26 - 27 - public static function getBuildStatusMap() { 28 - return array( 29 - self::STATUS_BUILDING => pht('Building'), 30 - self::STATUS_PASSED => pht('Passed'), 31 - self::STATUS_FAILED => pht('Failed'), 32 - ); 33 - } 34 - 35 - public static function getBuildableStatusIcon($status) { 36 - switch ($status) { 37 - case self::STATUS_BUILDING: 38 - return PHUIStatusItemView::ICON_RIGHT; 39 - case self::STATUS_PASSED: 40 - return PHUIStatusItemView::ICON_ACCEPT; 41 - case self::STATUS_FAILED: 42 - return PHUIStatusItemView::ICON_REJECT; 43 - default: 44 - return PHUIStatusItemView::ICON_QUESTION; 45 - } 46 - } 47 - 48 - public static function getBuildableStatusColor($status) { 49 - switch ($status) { 50 - case self::STATUS_BUILDING: 51 - return 'blue'; 52 - case self::STATUS_PASSED: 53 - return 'green'; 54 - case self::STATUS_FAILED: 55 - return 'red'; 56 - default: 57 - return 'bluegrey'; 58 - } 59 - } 60 - 61 - public function getStatusIcon() { 62 - return self::getBuildableStatusIcon($this->getBuildableStatus()); 63 - } 64 - 65 - public function getStatusDisplayName() { 66 - return self::getBuildableStatusName($this->getBuildableStatus()); 67 - } 68 - 69 - public function getStatusColor() { 70 - return self::getBuildableStatusColor($this->getBuildableStatus()); 71 - } 72 - 73 18 public static function initializeNewBuildable(PhabricatorUser $actor) { 74 19 return id(new HarbormasterBuildable()) 75 20 ->setIsManualBuildable(0) 76 - ->setBuildableStatus(self::STATUS_BUILDING); 21 + ->setBuildableStatus(HarbormasterBuildableStatus::STATUS_BUILDING); 77 22 } 78 23 79 24 public function getMonogram() { ··· 259 204 260 205 public function getBuilds() { 261 206 return $this->assertAttached($this->builds); 207 + } 208 + 209 + 210 + /* -( Status )------------------------------------------------------------- */ 211 + 212 + 213 + public function getBuildableStatusObject() { 214 + $status = $this->getBuildableStatus(); 215 + return HarbormasterBuildableStatus::newBuildableStatusObject($status); 216 + } 217 + 218 + public function getStatusIcon() { 219 + return $this->getBuildableStatusObject()->getIcon(); 220 + } 221 + 222 + public function getStatusDisplayName() { 223 + return $this->getBuildableStatusObject()->getDisplayName(); 224 + } 225 + 226 + public function getStatusColor() { 227 + return $this->getBuildableStatusObject()->getColor(); 262 228 } 263 229 264 230
+7 -7
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 512 512 break; 513 513 case PhabricatorTransactions::TYPE_BUILDABLE: 514 514 switch ($this->getNewValue()) { 515 - case HarbormasterBuildable::STATUS_PASSED: 515 + case HarbormasterBuildableStatus::STATUS_PASSED: 516 516 return 'green'; 517 - case HarbormasterBuildable::STATUS_FAILED: 517 + case HarbormasterBuildableStatus::STATUS_FAILED: 518 518 return 'red'; 519 519 } 520 520 break; ··· 676 676 return true; 677 677 case PhabricatorTransactions::TYPE_BUILDABLE: 678 678 switch ($this->getNewValue()) { 679 - case HarbormasterBuildable::STATUS_FAILED: 679 + case HarbormasterBuildableStatus::STATUS_FAILED: 680 680 // For now, only ever send mail when builds fail. We might let 681 681 // you customize this later, but in most cases this is probably 682 682 // completely uninteresting. ··· 739 739 return true; 740 740 case PhabricatorTransactions::TYPE_BUILDABLE: 741 741 switch ($this->getNewValue()) { 742 - case HarbormasterBuildable::STATUS_FAILED: 742 + case HarbormasterBuildableStatus::STATUS_FAILED: 743 743 // For now, don't notify on build passes either. These are pretty 744 744 // high volume and annoying, with very little present value. We 745 745 // might want to turn them back on in the specific case of ··· 1024 1024 1025 1025 case PhabricatorTransactions::TYPE_BUILDABLE: 1026 1026 switch ($this->getNewValue()) { 1027 - case HarbormasterBuildable::STATUS_BUILDING: 1027 + case HarbormasterBuildableStatus::STATUS_BUILDING: 1028 1028 return pht( 1029 1029 '%s started building %s.', 1030 1030 $this->renderHandleLink($author_phid), 1031 1031 $this->renderHandleLink( 1032 1032 $this->getMetadataValue('harbormaster:buildablePHID'))); 1033 - case HarbormasterBuildable::STATUS_PASSED: 1033 + case HarbormasterBuildableStatus::STATUS_PASSED: 1034 1034 return pht( 1035 1035 '%s completed building %s.', 1036 1036 $this->renderHandleLink($author_phid), 1037 1037 $this->renderHandleLink( 1038 1038 $this->getMetadataValue('harbormaster:buildablePHID'))); 1039 - case HarbormasterBuildable::STATUS_FAILED: 1039 + case HarbormasterBuildableStatus::STATUS_FAILED: 1040 1040 return pht( 1041 1041 '%s failed to build %s!', 1042 1042 $this->renderHandleLink($author_phid),