Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / harbormaster / constants / HarbormasterBuildStatus.php
blob009758078f31600cb18a76b9e7b3150d6f6ba1fd
1 <?php
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';
20 private $key;
21 private $properties;
23 public function __construct($key, array $properties) {
24 $this->key = $key;
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)) {
35 throw new Exception(
36 pht(
37 'Attempting to access unknown build status property ("%s").',
38 $key));
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');
96 /**
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() {
128 return array(
129 self::STATUS_INACTIVE,
130 self::STATUS_PENDING,
134 public static function getActiveStatusConstants() {
135 return array(
136 self::STATUS_BUILDING,
137 self::STATUS_PAUSED,
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;
151 return $constants;
154 public static function getCompletedStatusConstants() {
155 return array(
156 self::STATUS_PASSED,
157 self::STATUS_FAILED,
158 self::STATUS_ABORTED,
159 self::STATUS_ERROR,
160 self::STATUS_DEADLOCKED,
164 private static function getBuildStatusSpecMap() {
165 return array(
166 self::STATUS_INACTIVE => array(
167 'name' => pht('Inactive'),
168 'icon' => 'fa-circle-o',
169 'color' => 'dark',
170 'color.ansi' => 'yellow',
171 'isBuilding' => false,
172 'isComplete' => false,
174 self::STATUS_PENDING => array(
175 'name' => pht('Pending'),
176 'icon' => 'fa-circle-o',
177 'color' => 'blue',
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',
185 'color' => 'blue',
186 'color.ansi' => 'yellow',
187 'isBuilding' => true,
188 'isComplete' => false,
190 self::STATUS_PASSED => array(
191 'name' => pht('Passed'),
192 'icon' => 'fa-check-circle',
193 'color' => 'green',
194 'color.ansi' => 'green',
195 'isBuilding' => false,
196 'isComplete' => true,
198 self::STATUS_FAILED => array(
199 'name' => pht('Failed'),
200 'icon' => 'fa-times-circle',
201 'color' => 'red',
202 'color.ansi' => 'red',
203 'isBuilding' => false,
204 'isComplete' => true,
206 self::STATUS_ABORTED => array(
207 'name' => pht('Aborted'),
208 'icon' => 'fa-minus-circle',
209 'color' => 'red',
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',
217 'color' => 'red',
218 'color.ansi' => 'red',
219 'isBuilding' => false,
220 'isComplete' => true,
222 self::STATUS_PAUSED => array(
223 'name' => pht('Paused'),
224 'icon' => 'fa-pause',
225 'color' => 'yellow',
226 'color.ansi' => 'yellow',
227 'isBuilding' => false,
228 'isComplete' => false,
230 self::STATUS_DEADLOCKED => array(
231 'name' => pht('Deadlocked'),
232 'icon' => 'fa-exclamation-circle',
233 'color' => 'red',
234 'color.ansi' => 'red',
235 'isBuilding' => false,
236 'isComplete' => true,
238 self::PENDING_PAUSING => array(
239 'name' => pht('Pausing'),
240 'icon' => 'fa-exclamation-triangle',
241 'color' => 'red',
242 'color.ansi' => 'red',
243 'isBuilding' => false,
244 'isComplete' => false,
246 self::PENDING_RESUMING => array(
247 'name' => pht('Resuming'),
248 'icon' => 'fa-exclamation-triangle',
249 'color' => 'red',
250 'color.ansi' => 'red',
251 'isBuilding' => false,
252 'isComplete' => false,
254 self::PENDING_RESTARTING => array(
255 'name' => pht('Restarting'),
256 'icon' => 'fa-exclamation-triangle',
257 'color' => 'red',
258 'color.ansi' => 'red',
259 'isBuilding' => false,
260 'isComplete' => false,
262 self::PENDING_ABORTING => array(
263 'name' => pht('Aborting'),
264 'icon' => 'fa-exclamation-triangle',
265 'color' => 'red',
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];
279 return array(
280 'name' => pht('Unknown ("%s")', $status),
281 'icon' => 'fa-question-circle',
282 'color' => 'bluegrey',
283 'color.ansi' => 'magenta',
284 'isBuilding' => false,
285 'isComplete' => false,