Path: blob/master/src/applications/harbormaster/constants/HarbormasterBuildStatus.php
12256 views
<?php12final class HarbormasterBuildStatus extends Phobject {34const STATUS_INACTIVE = 'inactive';5const STATUS_PENDING = 'pending';6const STATUS_BUILDING = 'building';7const STATUS_PASSED = 'passed';8const STATUS_FAILED = 'failed';9const STATUS_ABORTED = 'aborted';10const STATUS_ERROR = 'error';11const STATUS_PAUSED = 'paused';12const STATUS_DEADLOCKED = 'deadlocked';1314const PENDING_PAUSING = 'x-pausing';15const PENDING_RESUMING = 'x-resuming';16const PENDING_RESTARTING = 'x-restarting';17const PENDING_ABORTING = 'x-aborting';1819private $key;20private $properties;2122public function __construct($key, array $properties) {23$this->key = $key;24$this->properties = $properties;25}2627public static function newBuildStatusObject($status) {28$spec = self::getBuildStatusSpec($status);29return new self($status, $spec);30}3132private function getProperty($key) {33if (!array_key_exists($key, $this->properties)) {34throw new Exception(35pht(36'Attempting to access unknown build status property ("%s").',37$key));38}3940return $this->properties[$key];41}4243public function isBuilding() {44return $this->getProperty('isBuilding');45}4647public function isPaused() {48return ($this->key === self::STATUS_PAUSED);49}5051public function isComplete() {52return $this->getProperty('isComplete');53}5455public function isPassed() {56return ($this->key === self::STATUS_PASSED);57}5859public function isFailed() {60return ($this->key === self::STATUS_FAILED);61}6263public function isAborting() {64return ($this->key === self::PENDING_ABORTING);65}6667public function isRestarting() {68return ($this->key === self::PENDING_RESTARTING);69}7071public function isResuming() {72return ($this->key === self::PENDING_RESUMING);73}7475public function isPausing() {76return ($this->key === self::PENDING_PAUSING);77}7879public function isPending() {80return ($this->key === self::STATUS_PENDING);81}8283public function getIconIcon() {84return $this->getProperty('icon');85}8687public function getIconColor() {88return $this->getProperty('color');89}9091public function getName() {92return $this->getProperty('name');93}9495/**96* Get a human readable name for a build status constant.97*98* @param const Build status constant.99* @return string Human-readable name.100*/101public static function getBuildStatusName($status) {102$spec = self::getBuildStatusSpec($status);103return $spec['name'];104}105106public static function getBuildStatusMap() {107$specs = self::getBuildStatusSpecMap();108return ipull($specs, 'name');109}110111public static function getBuildStatusIcon($status) {112$spec = self::getBuildStatusSpec($status);113return $spec['icon'];114}115116public static function getBuildStatusColor($status) {117$spec = self::getBuildStatusSpec($status);118return $spec['color'];119}120121public static function getBuildStatusANSIColor($status) {122$spec = self::getBuildStatusSpec($status);123return $spec['color.ansi'];124}125126public static function getWaitingStatusConstants() {127return array(128self::STATUS_INACTIVE,129self::STATUS_PENDING,130);131}132133public static function getActiveStatusConstants() {134return array(135self::STATUS_BUILDING,136self::STATUS_PAUSED,137);138}139140public static function getIncompleteStatusConstants() {141$map = self::getBuildStatusSpecMap();142143$constants = array();144foreach ($map as $constant => $spec) {145if (!$spec['isComplete']) {146$constants[] = $constant;147}148}149150return $constants;151}152153public static function getCompletedStatusConstants() {154return array(155self::STATUS_PASSED,156self::STATUS_FAILED,157self::STATUS_ABORTED,158self::STATUS_ERROR,159self::STATUS_DEADLOCKED,160);161}162163private static function getBuildStatusSpecMap() {164return array(165self::STATUS_INACTIVE => array(166'name' => pht('Inactive'),167'icon' => 'fa-circle-o',168'color' => 'dark',169'color.ansi' => 'yellow',170'isBuilding' => false,171'isComplete' => false,172),173self::STATUS_PENDING => array(174'name' => pht('Pending'),175'icon' => 'fa-circle-o',176'color' => 'blue',177'color.ansi' => 'yellow',178'isBuilding' => true,179'isComplete' => false,180),181self::STATUS_BUILDING => array(182'name' => pht('Building'),183'icon' => 'fa-chevron-circle-right',184'color' => 'blue',185'color.ansi' => 'yellow',186'isBuilding' => true,187'isComplete' => false,188),189self::STATUS_PASSED => array(190'name' => pht('Passed'),191'icon' => 'fa-check-circle',192'color' => 'green',193'color.ansi' => 'green',194'isBuilding' => false,195'isComplete' => true,196),197self::STATUS_FAILED => array(198'name' => pht('Failed'),199'icon' => 'fa-times-circle',200'color' => 'red',201'color.ansi' => 'red',202'isBuilding' => false,203'isComplete' => true,204),205self::STATUS_ABORTED => array(206'name' => pht('Aborted'),207'icon' => 'fa-minus-circle',208'color' => 'red',209'color.ansi' => 'red',210'isBuilding' => false,211'isComplete' => true,212),213self::STATUS_ERROR => array(214'name' => pht('Unexpected Error'),215'icon' => 'fa-minus-circle',216'color' => 'red',217'color.ansi' => 'red',218'isBuilding' => false,219'isComplete' => true,220),221self::STATUS_PAUSED => array(222'name' => pht('Paused'),223'icon' => 'fa-pause',224'color' => 'yellow',225'color.ansi' => 'yellow',226'isBuilding' => false,227'isComplete' => false,228),229self::STATUS_DEADLOCKED => array(230'name' => pht('Deadlocked'),231'icon' => 'fa-exclamation-circle',232'color' => 'red',233'color.ansi' => 'red',234'isBuilding' => false,235'isComplete' => true,236),237self::PENDING_PAUSING => array(238'name' => pht('Pausing'),239'icon' => 'fa-exclamation-triangle',240'color' => 'red',241'color.ansi' => 'red',242'isBuilding' => false,243'isComplete' => false,244),245self::PENDING_RESUMING => array(246'name' => pht('Resuming'),247'icon' => 'fa-exclamation-triangle',248'color' => 'red',249'color.ansi' => 'red',250'isBuilding' => false,251'isComplete' => false,252),253self::PENDING_RESTARTING => array(254'name' => pht('Restarting'),255'icon' => 'fa-exclamation-triangle',256'color' => 'red',257'color.ansi' => 'red',258'isBuilding' => false,259'isComplete' => false,260),261self::PENDING_ABORTING => array(262'name' => pht('Aborting'),263'icon' => 'fa-exclamation-triangle',264'color' => 'red',265'color.ansi' => 'red',266'isBuilding' => false,267'isComplete' => false,268),269);270}271272private static function getBuildStatusSpec($status) {273$map = self::getBuildStatusSpecMap();274if (isset($map[$status])) {275return $map[$status];276}277278return array(279'name' => pht('Unknown ("%s")', $status),280'icon' => 'fa-question-circle',281'color' => 'bluegrey',282'color.ansi' => 'magenta',283'isBuilding' => false,284'isComplete' => false,285);286}287288}289290291