@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.

at recaptime-dev/main 109 lines 2.7 kB view raw
1<?php 2 3final class HarbormasterBuildableStatus extends Phobject { 4 5 const STATUS_PREPARING = 'preparing'; 6 const STATUS_BUILDING = 'building'; 7 const STATUS_PASSED = 'passed'; 8 const STATUS_FAILED = 'failed'; 9 10 private $key; 11 private $properties; 12 13 public function __construct($key, array $properties) { 14 $this->key = $key; 15 $this->properties = $properties; 16 } 17 18 public static function newBuildableStatusObject($status) { 19 $spec = self::getSpecification($status); 20 return new self($status, $spec); 21 } 22 23 private function getProperty($key) { 24 if (!array_key_exists($key, $this->properties)) { 25 throw new Exception( 26 pht( 27 'Attempting to access unknown buildable status property ("%s").', 28 $key)); 29 } 30 31 return $this->properties[$key]; 32 } 33 34 public function getIcon() { 35 return $this->getProperty('icon'); 36 } 37 38 public function getDisplayName() { 39 return $this->getProperty('name'); 40 } 41 42 public function getActionName() { 43 return $this->getProperty('name.action'); 44 } 45 46 public function getColor() { 47 return $this->getProperty('color'); 48 } 49 50 public function isPreparing() { 51 return ($this->key === self::STATUS_PREPARING); 52 } 53 54 public function isBuilding() { 55 return ($this->key === self::STATUS_BUILDING); 56 } 57 58 public function isFailed() { 59 return ($this->key === self::STATUS_FAILED); 60 } 61 62 public static function getOptionMap() { 63 return ipull(self::getSpecifications(), 'name'); 64 } 65 66 private static function getSpecifications() { 67 return array( 68 self::STATUS_PREPARING => array( 69 'name' => pht('Preparing'), 70 'color' => 'blue', 71 'icon' => 'fa-hourglass-o', 72 'name.action' => pht('Build Preparing'), 73 ), 74 self::STATUS_BUILDING => array( 75 'name' => pht('Building'), 76 'color' => 'blue', 77 'icon' => 'fa-chevron-circle-right', 78 'name.action' => pht('Build Started'), 79 ), 80 self::STATUS_PASSED => array( 81 'name' => pht('Passed'), 82 'color' => 'green', 83 'icon' => 'fa-check-circle', 84 'name.action' => pht('Build Passed'), 85 ), 86 self::STATUS_FAILED => array( 87 'name' => pht('Failed'), 88 'color' => 'red', 89 'icon' => 'fa-times-circle', 90 'name.action' => pht('Build Failed'), 91 ), 92 ); 93 } 94 95 private static function getSpecification($status) { 96 $map = self::getSpecifications(); 97 if (isset($map[$status])) { 98 return $map[$status]; 99 } 100 101 return array( 102 'name' => pht('Unknown ("%s")', $status), 103 'icon' => 'fa-question-circle', 104 'color' => 'bluegrey', 105 'name.action' => pht('Build Status'), 106 ); 107 } 108 109}