1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

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
This commit is contained in:
epriestley 2014-04-17 16:00:58 -07:00
parent 3b0be0961c
commit 7c1bcdea16
6 changed files with 140 additions and 50 deletions

View file

@ -191,6 +191,7 @@ phutil_register_library_map(array(
'ConduitAPI_flag_query_Method' => 'applications/flag/conduit/ConduitAPI_flag_query_Method.php', 'ConduitAPI_flag_query_Method' => 'applications/flag/conduit/ConduitAPI_flag_query_Method.php',
'ConduitAPI_harbormaster_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_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_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_harbormaster_sendmessage_Method' => 'applications/harbormaster/conduit/ConduitAPI_harbormaster_sendmessage_Method.php',
'ConduitAPI_macro_Method' => 'applications/macro/conduit/ConduitAPI_macro_Method.php', 'ConduitAPI_macro_Method' => 'applications/macro/conduit/ConduitAPI_macro_Method.php',
'ConduitAPI_macro_creatememe_Method' => 'applications/macro/conduit/ConduitAPI_macro_creatememe_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_flag_query_Method' => 'ConduitAPI_flag_Method',
'ConduitAPI_harbormaster_Method' => 'ConduitAPIMethod', 'ConduitAPI_harbormaster_Method' => 'ConduitAPIMethod',
'ConduitAPI_harbormaster_querybuildables_Method' => 'ConduitAPI_harbormaster_Method', 'ConduitAPI_harbormaster_querybuildables_Method' => 'ConduitAPI_harbormaster_Method',
'ConduitAPI_harbormaster_querybuilds_Method' => 'ConduitAPI_harbormaster_Method',
'ConduitAPI_harbormaster_sendmessage_Method' => 'ConduitAPI_harbormaster_Method', 'ConduitAPI_harbormaster_sendmessage_Method' => 'ConduitAPI_harbormaster_Method',
'ConduitAPI_macro_Method' => 'ConduitAPIMethod', 'ConduitAPI_macro_Method' => 'ConduitAPIMethod',
'ConduitAPI_macro_creatememe_Method' => 'ConduitAPI_macro_Method', 'ConduitAPI_macro_creatememe_Method' => 'ConduitAPI_macro_Method',

View file

@ -0,0 +1,90 @@
<?php
final class ConduitAPI_harbormaster_querybuilds_Method
extends ConduitAPI_harbormaster_Method {
public function getMethodDescription() {
return pht('Query Harbormaster builds.');
}
public function defineParamTypes() {
return array(
'ids' => 'optional list<id>',
'phids' => 'optional list<phid>',
'buildStatuses' => 'optional list<string>',
'buildablePHIDs' => 'optional list<phid>',
'buildPlanPHIDs' => 'optional list<phid>',
) + 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;
}
}

View file

@ -308,26 +308,8 @@ final class HarbormasterBuildViewController
if ($build->isStopping()) { if ($build->isStopping()) {
return pht('Stopping'); return pht('Stopping');
} }
switch ($build->getBuildStatus()) {
case HarbormasterBuild::STATUS_INACTIVE: return HarbormasterBuild::getBuildStatusName($build->getBuildStatus());
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');
}
} }
private function buildMessages(array $messages) { private function buildMessages(array $messages) {

View file

@ -169,41 +169,33 @@ final class HarbormasterBuildableViewController
->setHeader($build->getName()) ->setHeader($build->getName())
->setHref($view_uri); ->setHref($view_uri);
switch ($build->getBuildStatus()) { $status = $build->getBuildStatus();
switch ($status) {
case HarbormasterBuild::STATUS_INACTIVE: case HarbormasterBuild::STATUS_INACTIVE:
$item->setBarColor('grey'); $item->setBarColor('grey');
$item->addAttribute(pht('Inactive'));
break; break;
case HarbormasterBuild::STATUS_PENDING: case HarbormasterBuild::STATUS_PENDING:
$item->setBarColor('blue'); $item->setBarColor('blue');
$item->addAttribute(pht('Pending'));
break;
case HarbormasterBuild::STATUS_WAITING:
$item->setBarColor('violet');
$item->addAttribute(pht('Waiting'));
break; break;
case HarbormasterBuild::STATUS_BUILDING: case HarbormasterBuild::STATUS_BUILDING:
$item->setBarColor('yellow'); $item->setBarColor('yellow');
$item->addAttribute(pht('Building'));
break; break;
case HarbormasterBuild::STATUS_PASSED: case HarbormasterBuild::STATUS_PASSED:
$item->setBarColor('green'); $item->setBarColor('green');
$item->addAttribute(pht('Passed'));
break; break;
case HarbormasterBuild::STATUS_FAILED: case HarbormasterBuild::STATUS_FAILED:
$item->setBarColor('red'); $item->setBarColor('red');
$item->addAttribute(pht('Failed'));
break; break;
case HarbormasterBuild::STATUS_ERROR: case HarbormasterBuild::STATUS_ERROR:
$item->setBarColor('red'); $item->setBarColor('red');
$item->addAttribute(pht('Unexpected Error'));
break; break;
case HarbormasterBuild::STATUS_STOPPED: case HarbormasterBuild::STATUS_STOPPED:
$item->setBarColor('black'); $item->setBarColor('black');
$item->addAttribute(pht('Stopped'));
break; break;
} }
$item->addAttribute(HarbormasterBuild::getBuildStatusName($status));
if ($build->isRestarting()) { if ($build->isRestarting()) {
$item->addIcon('backward', pht('Restarting')); $item->addIcon('backward', pht('Restarting'));
} else if ($build->isStopping()) { } else if ($build->isStopping()) {

View file

@ -72,36 +72,38 @@ final class HarbormasterUIEventListener
$item = new PHUIStatusItemView(); $item = new PHUIStatusItemView();
$item->setTarget($build_handles[$build->getPHID()]->renderLink()); $item->setTarget($build_handles[$build->getPHID()]->renderLink());
switch ($build->getBuildStatus()) { $status = $build->getBuildStatus();
$status_name = HarbormasterBuild::getBuildStatusName($status);
switch ($status) {
case HarbormasterBuild::STATUS_INACTIVE: case HarbormasterBuild::STATUS_INACTIVE:
$item->setIcon('open-dark', pht('Inactive')); $icon = 'open-dark';
break; break;
case HarbormasterBuild::STATUS_PENDING: case HarbormasterBuild::STATUS_PENDING:
$item->setIcon('open-blue', pht('Pending')); $icon = 'open-blue';
break;
case HarbormasterBuild::STATUS_WAITING:
$item->setIcon('up-blue', pht('Waiting on Resource'));
break; break;
case HarbormasterBuild::STATUS_BUILDING: case HarbormasterBuild::STATUS_BUILDING:
$item->setIcon('right-blue', pht('Building')); $icon = 'right-blue';
break; break;
case HarbormasterBuild::STATUS_PASSED: case HarbormasterBuild::STATUS_PASSED:
$item->setIcon('accept-green', pht('Passed')); $icon = 'accept-green';
break; break;
case HarbormasterBuild::STATUS_FAILED: case HarbormasterBuild::STATUS_FAILED:
$item->setIcon('reject-red', pht('Failed')); $icon = 'reject-red';
break; break;
case HarbormasterBuild::STATUS_ERROR: case HarbormasterBuild::STATUS_ERROR:
$item->setIcon('minus-red', pht('Unexpected Error')); $icon = 'minus-red';
break; break;
case HarbormasterBuild::STATUS_STOPPED: case HarbormasterBuild::STATUS_STOPPED:
$item->setIcon('minus-dark', pht('Stopped')); $icon = 'minus-dark';
break; break;
default: default:
$item->setIcon('question', pht('Unknown')); $icon = 'question';
break; break;
} }
$item->setIcon($icon, $status_name);
$status_view->addItem($item); $status_view->addItem($item);
} }

View file

@ -22,11 +22,6 @@ final class HarbormasterBuild extends HarbormasterDAO
*/ */
const STATUS_PENDING = 'pending'; const STATUS_PENDING = 'pending';
/**
* Waiting for a resource to be allocated (not yet relevant).
*/
const STATUS_WAITING = 'waiting';
/** /**
* Current building the buildable. * Current building the buildable.
*/ */
@ -52,6 +47,34 @@ final class HarbormasterBuild extends HarbormasterDAO
*/ */
const STATUS_STOPPED = 'stopped'; 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) { public static function initializeNewBuild(PhabricatorUser $actor) {
return id(new HarbormasterBuild()) return id(new HarbormasterBuild())
->setBuildStatus(self::STATUS_INACTIVE); ->setBuildStatus(self::STATUS_INACTIVE);
@ -114,7 +137,6 @@ final class HarbormasterBuild extends HarbormasterDAO
public function isBuilding() { public function isBuilding() {
return $this->getBuildStatus() === self::STATUS_PENDING || return $this->getBuildStatus() === self::STATUS_PENDING ||
$this->getBuildStatus() === self::STATUS_WAITING ||
$this->getBuildStatus() === self::STATUS_BUILDING; $this->getBuildStatus() === self::STATUS_BUILDING;
} }