Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/constants/HarbormasterBuildStatus.php
<?php | <?php | ||||
final class HarbormasterBuildStatus extends Phobject { | final class HarbormasterBuildStatus extends Phobject { | ||||
/** | |||||
* Not currently being built. | |||||
*/ | |||||
const STATUS_INACTIVE = 'inactive'; | const STATUS_INACTIVE = 'inactive'; | ||||
/** | |||||
* Pending pick up by the Harbormaster daemon. | |||||
*/ | |||||
const STATUS_PENDING = 'pending'; | const STATUS_PENDING = 'pending'; | ||||
/** | |||||
* Current building the buildable. | |||||
*/ | |||||
const STATUS_BUILDING = 'building'; | const STATUS_BUILDING = 'building'; | ||||
/** | |||||
* The build has passed. | |||||
*/ | |||||
const STATUS_PASSED = 'passed'; | const STATUS_PASSED = 'passed'; | ||||
/** | |||||
* The build has failed. | |||||
*/ | |||||
const STATUS_FAILED = 'failed'; | const STATUS_FAILED = 'failed'; | ||||
/** | |||||
* The build has aborted. | |||||
*/ | |||||
const STATUS_ABORTED = 'aborted'; | const STATUS_ABORTED = 'aborted'; | ||||
/** | |||||
* The build encountered an unexpected error. | |||||
*/ | |||||
const STATUS_ERROR = 'error'; | const STATUS_ERROR = 'error'; | ||||
/** | |||||
* The build has been paused. | |||||
*/ | |||||
const STATUS_PAUSED = 'paused'; | const STATUS_PAUSED = 'paused'; | ||||
/** | |||||
* The build has been deadlocked. | |||||
*/ | |||||
const STATUS_DEADLOCKED = 'deadlocked'; | const STATUS_DEADLOCKED = 'deadlocked'; | ||||
private $key; | |||||
private $properties; | |||||
public function __construct($key, array $properties) { | |||||
$this->key = $key; | |||||
$this->properties = $properties; | |||||
} | |||||
public static function newBuildStatusObject($status) { | |||||
$spec = self::getBuildStatusSpec($status); | |||||
return new self($status, $spec); | |||||
} | |||||
private function getProperty($key) { | |||||
if (!array_key_exists($key, $this->properties)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Attempting to access unknown build status property ("%s").', | |||||
$key)); | |||||
} | |||||
return $this->properties[$key]; | |||||
} | |||||
public function isBuilding() { | |||||
return $this->getProperty('isBuilding'); | |||||
} | |||||
public function isPaused() { | |||||
return ($this->key === self::STATUS_PAUSED); | |||||
} | |||||
public function isComplete() { | |||||
return $this->getProperty('isComplete'); | |||||
} | |||||
public function isPassed() { | |||||
return ($this->key === self::STATUS_PASSED); | |||||
} | |||||
/** | /** | ||||
* Get a human readable name for a build status constant. | * Get a human readable name for a build status constant. | ||||
* | * | ||||
* @param const Build status constant. | * @param const Build status constant. | ||||
* @return string Human-readable name. | * @return string Human-readable name. | ||||
*/ | */ | ||||
public static function getBuildStatusName($status) { | public static function getBuildStatusName($status) { | ||||
$spec = self::getBuildStatusSpec($status); | $spec = self::getBuildStatusSpec($status); | ||||
return idx($spec, 'name', pht('Unknown ("%s")', $status)); | return $spec['name']; | ||||
} | } | ||||
public static function getBuildStatusMap() { | public static function getBuildStatusMap() { | ||||
$specs = self::getBuildStatusSpecMap(); | $specs = self::getBuildStatusSpecMap(); | ||||
return ipull($specs, 'name'); | return ipull($specs, 'name'); | ||||
} | } | ||||
public static function getBuildStatusIcon($status) { | public static function getBuildStatusIcon($status) { | ||||
$spec = self::getBuildStatusSpec($status); | $spec = self::getBuildStatusSpec($status); | ||||
return idx($spec, 'icon', 'fa-question-circle'); | return $spec['icon']; | ||||
} | } | ||||
public static function getBuildStatusColor($status) { | public static function getBuildStatusColor($status) { | ||||
$spec = self::getBuildStatusSpec($status); | $spec = self::getBuildStatusSpec($status); | ||||
return idx($spec, 'color', 'bluegrey'); | return $spec['color']; | ||||
} | } | ||||
public static function getBuildStatusANSIColor($status) { | public static function getBuildStatusANSIColor($status) { | ||||
$spec = self::getBuildStatusSpec($status); | $spec = self::getBuildStatusSpec($status); | ||||
return idx($spec, 'color.ansi', 'magenta'); | return $spec['color.ansi']; | ||||
} | } | ||||
public static function getWaitingStatusConstants() { | public static function getWaitingStatusConstants() { | ||||
return array( | return array( | ||||
self::STATUS_INACTIVE, | self::STATUS_INACTIVE, | ||||
self::STATUS_PENDING, | self::STATUS_PENDING, | ||||
); | ); | ||||
} | } | ||||
Show All 17 Lines | final class HarbormasterBuildStatus extends Phobject { | ||||
private static function getBuildStatusSpecMap() { | private static function getBuildStatusSpecMap() { | ||||
return array( | return array( | ||||
self::STATUS_INACTIVE => array( | self::STATUS_INACTIVE => array( | ||||
'name' => pht('Inactive'), | 'name' => pht('Inactive'), | ||||
'icon' => 'fa-circle-o', | 'icon' => 'fa-circle-o', | ||||
'color' => 'dark', | 'color' => 'dark', | ||||
'color.ansi' => 'yellow', | 'color.ansi' => 'yellow', | ||||
'isBuilding' => false, | |||||
'isComplete' => false, | |||||
), | ), | ||||
self::STATUS_PENDING => array( | self::STATUS_PENDING => array( | ||||
'name' => pht('Pending'), | 'name' => pht('Pending'), | ||||
'icon' => 'fa-circle-o', | 'icon' => 'fa-circle-o', | ||||
'color' => 'blue', | 'color' => 'blue', | ||||
'color.ansi' => 'yellow', | 'color.ansi' => 'yellow', | ||||
'isBuilding' => true, | |||||
'isComplete' => false, | |||||
), | ), | ||||
self::STATUS_BUILDING => array( | self::STATUS_BUILDING => array( | ||||
'name' => pht('Building'), | 'name' => pht('Building'), | ||||
'icon' => 'fa-chevron-circle-right', | 'icon' => 'fa-chevron-circle-right', | ||||
'color' => 'blue', | 'color' => 'blue', | ||||
'color.ansi' => 'yellow', | 'color.ansi' => 'yellow', | ||||
'isBuilding' => true, | |||||
'isComplete' => false, | |||||
), | ), | ||||
self::STATUS_PASSED => array( | self::STATUS_PASSED => array( | ||||
'name' => pht('Passed'), | 'name' => pht('Passed'), | ||||
'icon' => 'fa-check-circle', | 'icon' => 'fa-check-circle', | ||||
'color' => 'green', | 'color' => 'green', | ||||
'color.ansi' => 'green', | 'color.ansi' => 'green', | ||||
'isBuilding' => false, | |||||
'isComplete' => true, | |||||
), | ), | ||||
self::STATUS_FAILED => array( | self::STATUS_FAILED => array( | ||||
'name' => pht('Failed'), | 'name' => pht('Failed'), | ||||
'icon' => 'fa-times-circle', | 'icon' => 'fa-times-circle', | ||||
'color' => 'red', | 'color' => 'red', | ||||
'color.ansi' => 'red', | 'color.ansi' => 'red', | ||||
'isBuilding' => false, | |||||
'isComplete' => true, | |||||
), | ), | ||||
self::STATUS_ABORTED => array( | self::STATUS_ABORTED => array( | ||||
'name' => pht('Aborted'), | 'name' => pht('Aborted'), | ||||
'icon' => 'fa-minus-circle', | 'icon' => 'fa-minus-circle', | ||||
'color' => 'red', | 'color' => 'red', | ||||
'color.ansi' => 'red', | 'color.ansi' => 'red', | ||||
'isBuilding' => false, | |||||
'isComplete' => true, | |||||
), | ), | ||||
self::STATUS_ERROR => array( | self::STATUS_ERROR => array( | ||||
'name' => pht('Unexpected Error'), | 'name' => pht('Unexpected Error'), | ||||
'icon' => 'fa-minus-circle', | 'icon' => 'fa-minus-circle', | ||||
'color' => 'red', | 'color' => 'red', | ||||
'color.ansi' => 'red', | 'color.ansi' => 'red', | ||||
'isBuilding' => false, | |||||
'isComplete' => true, | |||||
), | ), | ||||
self::STATUS_PAUSED => array( | self::STATUS_PAUSED => array( | ||||
'name' => pht('Paused'), | 'name' => pht('Paused'), | ||||
'icon' => 'fa-minus-circle', | 'icon' => 'fa-minus-circle', | ||||
'color' => 'dark', | 'color' => 'dark', | ||||
'color.ansi' => 'yellow', | 'color.ansi' => 'yellow', | ||||
'isBuilding' => false, | |||||
'isComplete' => false, | |||||
), | ), | ||||
self::STATUS_DEADLOCKED => array( | self::STATUS_DEADLOCKED => array( | ||||
'name' => pht('Deadlocked'), | 'name' => pht('Deadlocked'), | ||||
'icon' => 'fa-exclamation-circle', | 'icon' => 'fa-exclamation-circle', | ||||
'color' => 'red', | 'color' => 'red', | ||||
'color.ansi' => 'red', | 'color.ansi' => 'red', | ||||
'isBuilding' => false, | |||||
'isComplete' => true, | |||||
), | ), | ||||
); | ); | ||||
} | } | ||||
private static function getBuildStatusSpec($status) { | private static function getBuildStatusSpec($status) { | ||||
return idx(self::getBuildStatusSpecMap(), $status, array()); | $map = self::getBuildStatusSpecMap(); | ||||
if (isset($map[$status])) { | |||||
return $map[$status]; | |||||
} | |||||
return array( | |||||
'name' => pht('Unknown ("%s")', $status), | |||||
'icon' => 'fa-question-circle', | |||||
'color' => 'bluegrey', | |||||
'color.ansi' => 'magenta', | |||||
'isBuilding' => false, | |||||
'isComplete' => false, | |||||
); | |||||
} | } | ||||
} | } |