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

Provide ANSI color information for Harbormaster build status via API

Summary:
Ref PHI261. This moves Harbormaster build status to work more similarly to other modern status types, like Differential revision status, where we try to specify as much behavior on the server as possible so that the client and server can vary independently.

(I don't have any specific plans to make Harbormaster build status configurable on the server side, but it isn't out of the question.)

Test Plan: Ran `harbormaster.querybuilds` (saw same data as before) and `harbormaster.build.search` (saw same data as before, plus new ANSI color data).

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Differential Revision: https://secure.phabricator.com/D18838

+88 -52
+10
src/applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php
··· 65 65 $fields = idx($build_data, 'fields', array()); 66 66 unset($build_data['fields']); 67 67 unset($build_data['attachments']); 68 + 69 + // To retain backward compatibility, remove newer keys from the 70 + // result array. 71 + $fields['buildStatus'] = array_select_keys( 72 + $fields['buildStatus'], 73 + array( 74 + 'value', 75 + 'name', 76 + )); 77 + 68 78 $data[] = array_mergev(array($build_data, $querybuilds, $fields)); 69 79 } 70 80
+76 -52
src/applications/harbormaster/constants/HarbormasterBuildStatus.php
··· 55 55 * @return string Human-readable name. 56 56 */ 57 57 public static function getBuildStatusName($status) { 58 - $map = self::getBuildStatusMap(); 59 - return idx($map, $status, pht('Unknown ("%s")', $status)); 58 + $spec = self::getBuildStatusSpec($status); 59 + return idx($spec, 'name', pht('Unknown ("%s")', $status)); 60 60 } 61 61 62 62 public static function getBuildStatusMap() { 63 - return array( 64 - self::STATUS_INACTIVE => pht('Inactive'), 65 - self::STATUS_PENDING => pht('Pending'), 66 - self::STATUS_BUILDING => pht('Building'), 67 - self::STATUS_PASSED => pht('Passed'), 68 - self::STATUS_FAILED => pht('Failed'), 69 - self::STATUS_ABORTED => pht('Aborted'), 70 - self::STATUS_ERROR => pht('Unexpected Error'), 71 - self::STATUS_PAUSED => pht('Paused'), 72 - self::STATUS_DEADLOCKED => pht('Deadlocked'), 73 - ); 63 + $specs = self::getBuildStatusSpecMap(); 64 + return ipull($specs, 'name'); 74 65 } 75 66 76 67 public static function getBuildStatusIcon($status) { 77 - switch ($status) { 78 - case self::STATUS_INACTIVE: 79 - case self::STATUS_PENDING: 80 - return PHUIStatusItemView::ICON_OPEN; 81 - case self::STATUS_BUILDING: 82 - return PHUIStatusItemView::ICON_RIGHT; 83 - case self::STATUS_PASSED: 84 - return PHUIStatusItemView::ICON_ACCEPT; 85 - case self::STATUS_FAILED: 86 - return PHUIStatusItemView::ICON_REJECT; 87 - case self::STATUS_ABORTED: 88 - return PHUIStatusItemView::ICON_MINUS; 89 - case self::STATUS_ERROR: 90 - return PHUIStatusItemView::ICON_MINUS; 91 - case self::STATUS_PAUSED: 92 - return PHUIStatusItemView::ICON_MINUS; 93 - case self::STATUS_DEADLOCKED: 94 - return PHUIStatusItemView::ICON_WARNING; 95 - default: 96 - return PHUIStatusItemView::ICON_QUESTION; 97 - } 68 + $spec = self::getBuildStatusSpec($status); 69 + return idx($spec, 'icon', 'fa-question-circle'); 98 70 } 99 71 100 72 public static function getBuildStatusColor($status) { 101 - switch ($status) { 102 - case self::STATUS_INACTIVE: 103 - return 'dark'; 104 - case self::STATUS_PENDING: 105 - case self::STATUS_BUILDING: 106 - return 'blue'; 107 - case self::STATUS_PASSED: 108 - return 'green'; 109 - case self::STATUS_FAILED: 110 - case self::STATUS_ABORTED: 111 - case self::STATUS_ERROR: 112 - case self::STATUS_DEADLOCKED: 113 - return 'red'; 114 - case self::STATUS_PAUSED: 115 - return 'dark'; 116 - default: 117 - return 'bluegrey'; 118 - } 73 + $spec = self::getBuildStatusSpec($status); 74 + return idx($spec, 'color', 'bluegrey'); 75 + } 76 + 77 + public static function getBuildStatusANSIColor($status) { 78 + $spec = self::getBuildStatusSpec($status); 79 + return idx($spec, 'color.ansi', 'magenta'); 119 80 } 120 81 121 82 public static function getWaitingStatusConstants() { ··· 140 101 self::STATUS_ERROR, 141 102 self::STATUS_DEADLOCKED, 142 103 ); 104 + } 105 + 106 + private static function getBuildStatusSpecMap() { 107 + return array( 108 + self::STATUS_INACTIVE => array( 109 + 'name' => pht('Inactive'), 110 + 'icon' => 'fa-circle-o', 111 + 'color' => 'dark', 112 + 'color.ansi' => 'yellow', 113 + ), 114 + self::STATUS_PENDING => array( 115 + 'name' => pht('Pending'), 116 + 'icon' => 'fa-circle-o', 117 + 'color' => 'blue', 118 + 'color.ansi' => 'yellow', 119 + ), 120 + self::STATUS_BUILDING => array( 121 + 'name' => pht('Building'), 122 + 'icon' => 'fa-chevron-circle-right', 123 + 'color' => 'blue', 124 + 'color.ansi' => 'yellow', 125 + ), 126 + self::STATUS_PASSED => array( 127 + 'name' => pht('Passed'), 128 + 'icon' => 'fa-check-circle', 129 + 'color' => 'green', 130 + 'color.ansi' => 'green', 131 + ), 132 + self::STATUS_FAILED => array( 133 + 'name' => pht('Failed'), 134 + 'icon' => 'fa-times-circle', 135 + 'color' => 'red', 136 + 'color.ansi' => 'red', 137 + ), 138 + self::STATUS_ABORTED => array( 139 + 'name' => pht('Aborted'), 140 + 'icon' => 'fa-minus-circle', 141 + 'color' => 'red', 142 + 'color.ansi' => 'red', 143 + ), 144 + self::STATUS_ERROR => array( 145 + 'name' => pht('Unexpected Error'), 146 + 'icon' => 'fa-minus-circle', 147 + 'color' => 'red', 148 + 'color.ansi' => 'red', 149 + ), 150 + self::STATUS_PAUSED => array( 151 + 'name' => pht('Paused'), 152 + 'icon' => 'fa-minus-circle', 153 + 'color' => 'dark', 154 + 'color.ansi' => 'yellow', 155 + ), 156 + self::STATUS_DEADLOCKED => array( 157 + 'name' => pht('Deadlocked'), 158 + 'icon' => 'fa-exclamation-circle', 159 + 'color' => 'red', 160 + 'color.ansi' => 'red', 161 + ), 162 + ); 163 + } 164 + 165 + private static function getBuildStatusSpec($status) { 166 + return idx(self::getBuildStatusSpecMap(), $status, array()); 143 167 } 144 168 145 169 }
+2
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 435 435 'buildStatus' => array( 436 436 'value' => $status, 437 437 'name' => HarbormasterBuildStatus::getBuildStatusName($status), 438 + 'color.ansi' => 439 + HarbormasterBuildStatus::getBuildStatusANSIColor($status), 438 440 ), 439 441 'initiatorPHID' => nonempty($this->getInitiatorPHID(), null), 440 442 'name' => $this->getName(),