From 7c1bcdea1690672bbd0943093d1595e96e6dc525 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 17 Apr 2014 16:00:58 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + ...uitAPI_harbormaster_querybuilds_Method.php | 90 +++++++++++++++++++ .../HarbormasterBuildViewController.php | 22 +---- .../HarbormasterBuildableViewController.php | 16 +--- .../event/HarbormasterUIEventListener.php | 26 +++--- .../storage/build/HarbormasterBuild.php | 34 +++++-- 6 files changed, 140 insertions(+), 50 deletions(-) create mode 100644 src/applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d660781e85..36b58f8cc1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -191,6 +191,7 @@ phutil_register_library_map(array( 'ConduitAPI_flag_query_Method' => 'applications/flag/conduit/ConduitAPI_flag_query_Method.php', 'ConduitAPI_harbormaster_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_Method.php', 'ConduitAPI_harbormaster_querybuildables_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuildables_Method.php', + 'ConduitAPI_harbormaster_querybuilds_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php', 'ConduitAPI_harbormaster_sendmessage_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_sendmessage_Method.php', 'ConduitAPI_macro_Method' => 'applications/macro/conduit/ConduitAPI_macro_Method.php', 'ConduitAPI_macro_creatememe_Method' => 'applications/macro/conduit/ConduitAPI_macro_creatememe_Method.php', @@ -2781,6 +2782,7 @@ phutil_register_library_map(array( 'ConduitAPI_flag_query_Method' => 'ConduitAPI_flag_Method', 'ConduitAPI_harbormaster_Method' => 'ConduitAPIMethod', 'ConduitAPI_harbormaster_querybuildables_Method' => 'ConduitAPI_harbormaster_Method', + 'ConduitAPI_harbormaster_querybuilds_Method' => 'ConduitAPI_harbormaster_Method', 'ConduitAPI_harbormaster_sendmessage_Method' => 'ConduitAPI_harbormaster_Method', 'ConduitAPI_macro_Method' => 'ConduitAPIMethod', 'ConduitAPI_macro_creatememe_Method' => 'ConduitAPI_macro_Method', diff --git a/src/applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php b/src/applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php new file mode 100644 index 0000000000..58120e05c7 --- /dev/null +++ b/src/applications/harbormaster/conduit/ConduitAPI_harbormaster_querybuilds_Method.php @@ -0,0 +1,90 @@ + 'optional list', + 'phids' => 'optional list', + 'buildStatuses' => 'optional list', + 'buildablePHIDs' => 'optional list', + 'buildPlanPHIDs' => 'optional list', + ) + self::getPagerParamTypes(); + } + + public function defineReturnType() { + return 'wild'; + } + + public function defineErrorTypes() { + return array(); + } + + protected function execute(ConduitAPIRequest $request) { + $viewer = $request->getUser(); + + $query = id(new HarbormasterBuildQuery()) + ->setViewer($viewer); + + $ids = $request->getValue('ids'); + if ($ids !== null) { + $query->withIDs($ids); + } + + $phids = $request->getValue('phids'); + if ($phids !== null) { + $query->withPHIDs($phids); + } + + $statuses = $request->getValue('buildStatuses'); + if ($statuses !== null) { + $query->withBuildStatuses($statuses); + } + + $buildable_phids = $request->getValue('buildablePHIDs'); + if ($buildable_phids !== null) { + $query->withBuildablePHIDs($buildable_phids); + } + + $build_plan_phids = $request->getValue('buildPlanPHIDs'); + if ($build_plan_phids !== null) { + $query->withBuildPlanPHIDs($build_plan_phids); + } + + $pager = $this->newPager($request); + + $builds = $query->executeWithCursorPager($pager); + + $data = array(); + foreach ($builds as $build) { + + $id = $build->getID(); + $uri = '/harbormaster/build/'.$id.'/'; + $status = $build->getBuildStatus(); + + $data[] = array( + 'id' => $id, + 'phid' => $build->getPHID(), + 'uri' => PhabricatorEnv::getProductionURI($uri), + 'name' => $build->getBuildPlan()->getName(), + 'buildablePHID' => $build->getBuildablePHID(), + 'buildPlanPHID' => $build->getBuildPlanPHID(), + 'buildStatus' => $status, + 'buildStatusName' => HarbormasterBuild::getBuildStatusName($status), + ); + } + + $results = array( + 'data' => $data, + ); + + $results = $this->addPagerResults($results, $pager); + return $results; + } + +} diff --git a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php index c8387f76c8..0a4a65fc23 100644 --- a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php +++ b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php @@ -308,26 +308,8 @@ final class HarbormasterBuildViewController if ($build->isStopping()) { return pht('Stopping'); } - switch ($build->getBuildStatus()) { - case HarbormasterBuild::STATUS_INACTIVE: - return pht('Inactive'); - case HarbormasterBuild::STATUS_PENDING: - return pht('Pending'); - case HarbormasterBuild::STATUS_WAITING: - return pht('Waiting'); - case HarbormasterBuild::STATUS_BUILDING: - return pht('Building'); - case HarbormasterBuild::STATUS_PASSED: - return pht('Passed'); - case HarbormasterBuild::STATUS_FAILED: - return pht('Failed'); - case HarbormasterBuild::STATUS_ERROR: - return pht('Unexpected Error'); - case HarbormasterBuild::STATUS_STOPPED: - return pht('Stopped'); - default: - return pht('Unknown'); - } + + return HarbormasterBuild::getBuildStatusName($build->getBuildStatus()); } private function buildMessages(array $messages) { diff --git a/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php index 7b2b868f1b..dcc68da6f4 100644 --- a/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php +++ b/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php @@ -169,41 +169,33 @@ final class HarbormasterBuildableViewController ->setHeader($build->getName()) ->setHref($view_uri); - switch ($build->getBuildStatus()) { + $status = $build->getBuildStatus(); + switch ($status) { case HarbormasterBuild::STATUS_INACTIVE: $item->setBarColor('grey'); - $item->addAttribute(pht('Inactive')); break; case HarbormasterBuild::STATUS_PENDING: $item->setBarColor('blue'); - $item->addAttribute(pht('Pending')); - break; - case HarbormasterBuild::STATUS_WAITING: - $item->setBarColor('violet'); - $item->addAttribute(pht('Waiting')); break; case HarbormasterBuild::STATUS_BUILDING: $item->setBarColor('yellow'); - $item->addAttribute(pht('Building')); break; case HarbormasterBuild::STATUS_PASSED: $item->setBarColor('green'); - $item->addAttribute(pht('Passed')); break; case HarbormasterBuild::STATUS_FAILED: $item->setBarColor('red'); - $item->addAttribute(pht('Failed')); break; case HarbormasterBuild::STATUS_ERROR: $item->setBarColor('red'); - $item->addAttribute(pht('Unexpected Error')); break; case HarbormasterBuild::STATUS_STOPPED: $item->setBarColor('black'); - $item->addAttribute(pht('Stopped')); break; } + $item->addAttribute(HarbormasterBuild::getBuildStatusName($status)); + if ($build->isRestarting()) { $item->addIcon('backward', pht('Restarting')); } else if ($build->isStopping()) { diff --git a/src/applications/harbormaster/event/HarbormasterUIEventListener.php b/src/applications/harbormaster/event/HarbormasterUIEventListener.php index 2a6fee9af3..72ffbf7970 100644 --- a/src/applications/harbormaster/event/HarbormasterUIEventListener.php +++ b/src/applications/harbormaster/event/HarbormasterUIEventListener.php @@ -72,36 +72,38 @@ final class HarbormasterUIEventListener $item = new PHUIStatusItemView(); $item->setTarget($build_handles[$build->getPHID()]->renderLink()); - switch ($build->getBuildStatus()) { + $status = $build->getBuildStatus(); + $status_name = HarbormasterBuild::getBuildStatusName($status); + + switch ($status) { case HarbormasterBuild::STATUS_INACTIVE: - $item->setIcon('open-dark', pht('Inactive')); + $icon = 'open-dark'; break; case HarbormasterBuild::STATUS_PENDING: - $item->setIcon('open-blue', pht('Pending')); - break; - case HarbormasterBuild::STATUS_WAITING: - $item->setIcon('up-blue', pht('Waiting on Resource')); + $icon = 'open-blue'; break; case HarbormasterBuild::STATUS_BUILDING: - $item->setIcon('right-blue', pht('Building')); + $icon = 'right-blue'; break; case HarbormasterBuild::STATUS_PASSED: - $item->setIcon('accept-green', pht('Passed')); + $icon = 'accept-green'; break; case HarbormasterBuild::STATUS_FAILED: - $item->setIcon('reject-red', pht('Failed')); + $icon = 'reject-red'; break; case HarbormasterBuild::STATUS_ERROR: - $item->setIcon('minus-red', pht('Unexpected Error')); + $icon = 'minus-red'; break; case HarbormasterBuild::STATUS_STOPPED: - $item->setIcon('minus-dark', pht('Stopped')); + $icon = 'minus-dark'; break; default: - $item->setIcon('question', pht('Unknown')); + $icon = 'question'; break; } + $item->setIcon($icon, $status_name); + $status_view->addItem($item); } diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php index 7133cee071..2048b703ab 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -22,11 +22,6 @@ final class HarbormasterBuild extends HarbormasterDAO */ const STATUS_PENDING = 'pending'; - /** - * Waiting for a resource to be allocated (not yet relevant). - */ - const STATUS_WAITING = 'waiting'; - /** * Current building the buildable. */ @@ -52,6 +47,34 @@ final class HarbormasterBuild extends HarbormasterDAO */ const STATUS_STOPPED = 'stopped'; + + /** + * Get a human readable name for a build status constant. + * + * @param const Build status constant. + * @return string Human-readable name. + */ + public static function getBuildStatusName($status) { + switch ($status) { + case self::STATUS_INACTIVE: + return pht('Inactive'); + case self::STATUS_PENDING: + return pht('Pending'); + case self::STATUS_BUILDING: + return pht('Building'); + case self::STATUS_PASSED: + return pht('Passed'); + case self::STATUS_FAILED: + return pht('Failed'); + case self::STATUS_ERROR: + return pht('Unexpected Error'); + case self::STATUS_STOPPED: + return pht('Stopped'); + default: + return pht('Unknown'); + } + } + public static function initializeNewBuild(PhabricatorUser $actor) { return id(new HarbormasterBuild()) ->setBuildStatus(self::STATUS_INACTIVE); @@ -114,7 +137,6 @@ final class HarbormasterBuild extends HarbormasterDAO public function isBuilding() { return $this->getBuildStatus() === self::STATUS_PENDING || - $this->getBuildStatus() === self::STATUS_WAITING || $this->getBuildStatus() === self::STATUS_BUILDING; }