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

Add "harbormaster.querybuilds" Conduit API

Summary:
Ref T4809. This one is more straightforward. A couple of tweaks:

- Remove the WAITING status, since nothing ever sets it and I suspect nothing ever will with the modern way artifacts work (maybe). At a minimum, it's confusing with the new Target status that's also called "WAITING" but means something different.
- Consolidate 17 copies of these status names into one method.

Test Plan: Ran some queries via Conduit, got reasonable looking results.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4809

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

+140 -50
+2
src/__phutil_library_map__.php
··· 191 191 'ConduitAPI_flag_query_Method' => 'applications/flag/conduit/ConduitAPI_flag_query_Method.php', 192 192 'ConduitAPI_harbormaster_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_Method.php', 193 193 'ConduitAPI_harbormaster_querybuildables_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuildables_Method.php', 194 + 'ConduitAPI_harbormaster_querybuilds_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php', 194 195 'ConduitAPI_harbormaster_sendmessage_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_sendmessage_Method.php', 195 196 'ConduitAPI_macro_Method' => 'applications/macro/conduit/ConduitAPI_macro_Method.php', 196 197 'ConduitAPI_macro_creatememe_Method' => 'applications/macro/conduit/ConduitAPI_macro_creatememe_Method.php', ··· 2781 2782 'ConduitAPI_flag_query_Method' => 'ConduitAPI_flag_Method', 2782 2783 'ConduitAPI_harbormaster_Method' => 'ConduitAPIMethod', 2783 2784 'ConduitAPI_harbormaster_querybuildables_Method' => 'ConduitAPI_harbormaster_Method', 2785 + 'ConduitAPI_harbormaster_querybuilds_Method' => 'ConduitAPI_harbormaster_Method', 2784 2786 'ConduitAPI_harbormaster_sendmessage_Method' => 'ConduitAPI_harbormaster_Method', 2785 2787 'ConduitAPI_macro_Method' => 'ConduitAPIMethod', 2786 2788 'ConduitAPI_macro_creatememe_Method' => 'ConduitAPI_macro_Method',
+90
src/applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php
··· 1 + <?php 2 + 3 + final class ConduitAPI_harbormaster_querybuilds_Method 4 + extends ConduitAPI_harbormaster_Method { 5 + 6 + public function getMethodDescription() { 7 + return pht('Query Harbormaster builds.'); 8 + } 9 + 10 + public function defineParamTypes() { 11 + return array( 12 + 'ids' => 'optional list<id>', 13 + 'phids' => 'optional list<phid>', 14 + 'buildStatuses' => 'optional list<string>', 15 + 'buildablePHIDs' => 'optional list<phid>', 16 + 'buildPlanPHIDs' => 'optional list<phid>', 17 + ) + self::getPagerParamTypes(); 18 + } 19 + 20 + public function defineReturnType() { 21 + return 'wild'; 22 + } 23 + 24 + public function defineErrorTypes() { 25 + return array(); 26 + } 27 + 28 + protected function execute(ConduitAPIRequest $request) { 29 + $viewer = $request->getUser(); 30 + 31 + $query = id(new HarbormasterBuildQuery()) 32 + ->setViewer($viewer); 33 + 34 + $ids = $request->getValue('ids'); 35 + if ($ids !== null) { 36 + $query->withIDs($ids); 37 + } 38 + 39 + $phids = $request->getValue('phids'); 40 + if ($phids !== null) { 41 + $query->withPHIDs($phids); 42 + } 43 + 44 + $statuses = $request->getValue('buildStatuses'); 45 + if ($statuses !== null) { 46 + $query->withBuildStatuses($statuses); 47 + } 48 + 49 + $buildable_phids = $request->getValue('buildablePHIDs'); 50 + if ($buildable_phids !== null) { 51 + $query->withBuildablePHIDs($buildable_phids); 52 + } 53 + 54 + $build_plan_phids = $request->getValue('buildPlanPHIDs'); 55 + if ($build_plan_phids !== null) { 56 + $query->withBuildPlanPHIDs($build_plan_phids); 57 + } 58 + 59 + $pager = $this->newPager($request); 60 + 61 + $builds = $query->executeWithCursorPager($pager); 62 + 63 + $data = array(); 64 + foreach ($builds as $build) { 65 + 66 + $id = $build->getID(); 67 + $uri = '/harbormaster/build/'.$id.'/'; 68 + $status = $build->getBuildStatus(); 69 + 70 + $data[] = array( 71 + 'id' => $id, 72 + 'phid' => $build->getPHID(), 73 + 'uri' => PhabricatorEnv::getProductionURI($uri), 74 + 'name' => $build->getBuildPlan()->getName(), 75 + 'buildablePHID' => $build->getBuildablePHID(), 76 + 'buildPlanPHID' => $build->getBuildPlanPHID(), 77 + 'buildStatus' => $status, 78 + 'buildStatusName' => HarbormasterBuild::getBuildStatusName($status), 79 + ); 80 + } 81 + 82 + $results = array( 83 + 'data' => $data, 84 + ); 85 + 86 + $results = $this->addPagerResults($results, $pager); 87 + return $results; 88 + } 89 + 90 + }
+2 -20
src/applications/harbormaster/controller/HarbormasterBuildViewController.php
··· 308 308 if ($build->isStopping()) { 309 309 return pht('Stopping'); 310 310 } 311 - switch ($build->getBuildStatus()) { 312 - case HarbormasterBuild::STATUS_INACTIVE: 313 - return pht('Inactive'); 314 - case HarbormasterBuild::STATUS_PENDING: 315 - return pht('Pending'); 316 - case HarbormasterBuild::STATUS_WAITING: 317 - return pht('Waiting'); 318 - case HarbormasterBuild::STATUS_BUILDING: 319 - return pht('Building'); 320 - case HarbormasterBuild::STATUS_PASSED: 321 - return pht('Passed'); 322 - case HarbormasterBuild::STATUS_FAILED: 323 - return pht('Failed'); 324 - case HarbormasterBuild::STATUS_ERROR: 325 - return pht('Unexpected Error'); 326 - case HarbormasterBuild::STATUS_STOPPED: 327 - return pht('Stopped'); 328 - default: 329 - return pht('Unknown'); 330 - } 311 + 312 + return HarbormasterBuild::getBuildStatusName($build->getBuildStatus()); 331 313 } 332 314 333 315 private function buildMessages(array $messages) {
+4 -12
src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
··· 169 169 ->setHeader($build->getName()) 170 170 ->setHref($view_uri); 171 171 172 - switch ($build->getBuildStatus()) { 172 + $status = $build->getBuildStatus(); 173 + switch ($status) { 173 174 case HarbormasterBuild::STATUS_INACTIVE: 174 175 $item->setBarColor('grey'); 175 - $item->addAttribute(pht('Inactive')); 176 176 break; 177 177 case HarbormasterBuild::STATUS_PENDING: 178 178 $item->setBarColor('blue'); 179 - $item->addAttribute(pht('Pending')); 180 - break; 181 - case HarbormasterBuild::STATUS_WAITING: 182 - $item->setBarColor('violet'); 183 - $item->addAttribute(pht('Waiting')); 184 179 break; 185 180 case HarbormasterBuild::STATUS_BUILDING: 186 181 $item->setBarColor('yellow'); 187 - $item->addAttribute(pht('Building')); 188 182 break; 189 183 case HarbormasterBuild::STATUS_PASSED: 190 184 $item->setBarColor('green'); 191 - $item->addAttribute(pht('Passed')); 192 185 break; 193 186 case HarbormasterBuild::STATUS_FAILED: 194 187 $item->setBarColor('red'); 195 - $item->addAttribute(pht('Failed')); 196 188 break; 197 189 case HarbormasterBuild::STATUS_ERROR: 198 190 $item->setBarColor('red'); 199 - $item->addAttribute(pht('Unexpected Error')); 200 191 break; 201 192 case HarbormasterBuild::STATUS_STOPPED: 202 193 $item->setBarColor('black'); 203 - $item->addAttribute(pht('Stopped')); 204 194 break; 205 195 } 196 + 197 + $item->addAttribute(HarbormasterBuild::getBuildStatusName($status)); 206 198 207 199 if ($build->isRestarting()) { 208 200 $item->addIcon('backward', pht('Restarting'));
+14 -12
src/applications/harbormaster/event/HarbormasterUIEventListener.php
··· 72 72 $item = new PHUIStatusItemView(); 73 73 $item->setTarget($build_handles[$build->getPHID()]->renderLink()); 74 74 75 - switch ($build->getBuildStatus()) { 75 + $status = $build->getBuildStatus(); 76 + $status_name = HarbormasterBuild::getBuildStatusName($status); 77 + 78 + switch ($status) { 76 79 case HarbormasterBuild::STATUS_INACTIVE: 77 - $item->setIcon('open-dark', pht('Inactive')); 80 + $icon = 'open-dark'; 78 81 break; 79 82 case HarbormasterBuild::STATUS_PENDING: 80 - $item->setIcon('open-blue', pht('Pending')); 81 - break; 82 - case HarbormasterBuild::STATUS_WAITING: 83 - $item->setIcon('up-blue', pht('Waiting on Resource')); 83 + $icon = 'open-blue'; 84 84 break; 85 85 case HarbormasterBuild::STATUS_BUILDING: 86 - $item->setIcon('right-blue', pht('Building')); 86 + $icon = 'right-blue'; 87 87 break; 88 88 case HarbormasterBuild::STATUS_PASSED: 89 - $item->setIcon('accept-green', pht('Passed')); 89 + $icon = 'accept-green'; 90 90 break; 91 91 case HarbormasterBuild::STATUS_FAILED: 92 - $item->setIcon('reject-red', pht('Failed')); 92 + $icon = 'reject-red'; 93 93 break; 94 94 case HarbormasterBuild::STATUS_ERROR: 95 - $item->setIcon('minus-red', pht('Unexpected Error')); 95 + $icon = 'minus-red'; 96 96 break; 97 97 case HarbormasterBuild::STATUS_STOPPED: 98 - $item->setIcon('minus-dark', pht('Stopped')); 98 + $icon = 'minus-dark'; 99 99 break; 100 100 default: 101 - $item->setIcon('question', pht('Unknown')); 101 + $icon = 'question'; 102 102 break; 103 103 } 104 + 105 + $item->setIcon($icon, $status_name); 104 106 105 107 106 108 $status_view->addItem($item);
+28 -6
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 23 23 const STATUS_PENDING = 'pending'; 24 24 25 25 /** 26 - * Waiting for a resource to be allocated (not yet relevant). 27 - */ 28 - const STATUS_WAITING = 'waiting'; 29 - 30 - /** 31 26 * Current building the buildable. 32 27 */ 33 28 const STATUS_BUILDING = 'building'; ··· 51 46 * The build has been stopped. 52 47 */ 53 48 const STATUS_STOPPED = 'stopped'; 49 + 50 + 51 + /** 52 + * Get a human readable name for a build status constant. 53 + * 54 + * @param const Build status constant. 55 + * @return string Human-readable name. 56 + */ 57 + public static function getBuildStatusName($status) { 58 + switch ($status) { 59 + case self::STATUS_INACTIVE: 60 + return pht('Inactive'); 61 + case self::STATUS_PENDING: 62 + return pht('Pending'); 63 + case self::STATUS_BUILDING: 64 + return pht('Building'); 65 + case self::STATUS_PASSED: 66 + return pht('Passed'); 67 + case self::STATUS_FAILED: 68 + return pht('Failed'); 69 + case self::STATUS_ERROR: 70 + return pht('Unexpected Error'); 71 + case self::STATUS_STOPPED: 72 + return pht('Stopped'); 73 + default: 74 + return pht('Unknown'); 75 + } 76 + } 54 77 55 78 public static function initializeNewBuild(PhabricatorUser $actor) { 56 79 return id(new HarbormasterBuild()) ··· 114 137 115 138 public function isBuilding() { 116 139 return $this->getBuildStatus() === self::STATUS_PENDING || 117 - $this->getBuildStatus() === self::STATUS_WAITING || 118 140 $this->getBuildStatus() === self::STATUS_BUILDING; 119 141 } 120 142