3 final class HarbormasterBuildStatus
extends Phobject
{
5 const STATUS_INACTIVE
= 'inactive';
6 const STATUS_PENDING
= 'pending';
7 const STATUS_BUILDING
= 'building';
8 const STATUS_PASSED
= 'passed';
9 const STATUS_FAILED
= 'failed';
10 const STATUS_ABORTED
= 'aborted';
11 const STATUS_ERROR
= 'error';
12 const STATUS_PAUSED
= 'paused';
13 const STATUS_DEADLOCKED
= 'deadlocked';
15 const PENDING_PAUSING
= 'x-pausing';
16 const PENDING_RESUMING
= 'x-resuming';
17 const PENDING_RESTARTING
= 'x-restarting';
18 const PENDING_ABORTING
= 'x-aborting';
23 public function __construct($key, array $properties) {
25 $this->properties
= $properties;
28 public static function newBuildStatusObject($status) {
29 $spec = self
::getBuildStatusSpec($status);
30 return new self($status, $spec);
33 private function getProperty($key) {
34 if (!array_key_exists($key, $this->properties
)) {
37 'Attempting to access unknown build status property ("%s").',
41 return $this->properties
[$key];
44 public function isBuilding() {
45 return $this->getProperty('isBuilding');
48 public function isPaused() {
49 return ($this->key
=== self
::STATUS_PAUSED
);
52 public function isComplete() {
53 return $this->getProperty('isComplete');
56 public function isPassed() {
57 return ($this->key
=== self
::STATUS_PASSED
);
60 public function isFailed() {
61 return ($this->key
=== self
::STATUS_FAILED
);
64 public function isAborting() {
65 return ($this->key
=== self
::PENDING_ABORTING
);
68 public function isRestarting() {
69 return ($this->key
=== self
::PENDING_RESTARTING
);
72 public function isResuming() {
73 return ($this->key
=== self
::PENDING_RESUMING
);
76 public function isPausing() {
77 return ($this->key
=== self
::PENDING_PAUSING
);
80 public function isPending() {
81 return ($this->key
=== self
::STATUS_PENDING
);
84 public function getIconIcon() {
85 return $this->getProperty('icon');
88 public function getIconColor() {
89 return $this->getProperty('color');
92 public function getName() {
93 return $this->getProperty('name');
97 * Get a human readable name for a build status constant.
99 * @param const Build status constant.
100 * @return string Human-readable name.
102 public static function getBuildStatusName($status) {
103 $spec = self
::getBuildStatusSpec($status);
104 return $spec['name'];
107 public static function getBuildStatusMap() {
108 $specs = self
::getBuildStatusSpecMap();
109 return ipull($specs, 'name');
112 public static function getBuildStatusIcon($status) {
113 $spec = self
::getBuildStatusSpec($status);
114 return $spec['icon'];
117 public static function getBuildStatusColor($status) {
118 $spec = self
::getBuildStatusSpec($status);
119 return $spec['color'];
122 public static function getBuildStatusANSIColor($status) {
123 $spec = self
::getBuildStatusSpec($status);
124 return $spec['color.ansi'];
127 public static function getWaitingStatusConstants() {
129 self
::STATUS_INACTIVE
,
130 self
::STATUS_PENDING
,
134 public static function getActiveStatusConstants() {
136 self
::STATUS_BUILDING
,
141 public static function getIncompleteStatusConstants() {
142 $map = self
::getBuildStatusSpecMap();
144 $constants = array();
145 foreach ($map as $constant => $spec) {
146 if (!$spec['isComplete']) {
147 $constants[] = $constant;
154 public static function getCompletedStatusConstants() {
158 self
::STATUS_ABORTED
,
160 self
::STATUS_DEADLOCKED
,
164 private static function getBuildStatusSpecMap() {
166 self
::STATUS_INACTIVE
=> array(
167 'name' => pht('Inactive'),
168 'icon' => 'fa-circle-o',
170 'color.ansi' => 'yellow',
171 'isBuilding' => false,
172 'isComplete' => false,
174 self
::STATUS_PENDING
=> array(
175 'name' => pht('Pending'),
176 'icon' => 'fa-circle-o',
178 'color.ansi' => 'yellow',
179 'isBuilding' => true,
180 'isComplete' => false,
182 self
::STATUS_BUILDING
=> array(
183 'name' => pht('Building'),
184 'icon' => 'fa-chevron-circle-right',
186 'color.ansi' => 'yellow',
187 'isBuilding' => true,
188 'isComplete' => false,
190 self
::STATUS_PASSED
=> array(
191 'name' => pht('Passed'),
192 'icon' => 'fa-check-circle',
194 'color.ansi' => 'green',
195 'isBuilding' => false,
196 'isComplete' => true,
198 self
::STATUS_FAILED
=> array(
199 'name' => pht('Failed'),
200 'icon' => 'fa-times-circle',
202 'color.ansi' => 'red',
203 'isBuilding' => false,
204 'isComplete' => true,
206 self
::STATUS_ABORTED
=> array(
207 'name' => pht('Aborted'),
208 'icon' => 'fa-minus-circle',
210 'color.ansi' => 'red',
211 'isBuilding' => false,
212 'isComplete' => true,
214 self
::STATUS_ERROR
=> array(
215 'name' => pht('Unexpected Error'),
216 'icon' => 'fa-minus-circle',
218 'color.ansi' => 'red',
219 'isBuilding' => false,
220 'isComplete' => true,
222 self
::STATUS_PAUSED
=> array(
223 'name' => pht('Paused'),
224 'icon' => 'fa-pause',
226 'color.ansi' => 'yellow',
227 'isBuilding' => false,
228 'isComplete' => false,
230 self
::STATUS_DEADLOCKED
=> array(
231 'name' => pht('Deadlocked'),
232 'icon' => 'fa-exclamation-circle',
234 'color.ansi' => 'red',
235 'isBuilding' => false,
236 'isComplete' => true,
238 self
::PENDING_PAUSING
=> array(
239 'name' => pht('Pausing'),
240 'icon' => 'fa-exclamation-triangle',
242 'color.ansi' => 'red',
243 'isBuilding' => false,
244 'isComplete' => false,
246 self
::PENDING_RESUMING
=> array(
247 'name' => pht('Resuming'),
248 'icon' => 'fa-exclamation-triangle',
250 'color.ansi' => 'red',
251 'isBuilding' => false,
252 'isComplete' => false,
254 self
::PENDING_RESTARTING
=> array(
255 'name' => pht('Restarting'),
256 'icon' => 'fa-exclamation-triangle',
258 'color.ansi' => 'red',
259 'isBuilding' => false,
260 'isComplete' => false,
262 self
::PENDING_ABORTING
=> array(
263 'name' => pht('Aborting'),
264 'icon' => 'fa-exclamation-triangle',
266 'color.ansi' => 'red',
267 'isBuilding' => false,
268 'isComplete' => false,
273 private static function getBuildStatusSpec($status) {
274 $map = self
::getBuildStatusSpecMap();
275 if (isset($map[$status])) {
276 return $map[$status];
280 'name' => pht('Unknown ("%s")', $status),
281 'icon' => 'fa-question-circle',
282 'color' => 'bluegrey',
283 'color.ansi' => 'magenta',
284 'isBuilding' => false,
285 'isComplete' => false,