From 01c7be059dd6fd806dd2f1fcea7f0d602b6ca43c Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 26 Nov 2018 06:25:22 -0800 Subject: [PATCH] Add support for "harbormaster.target.search" Summary: Ref T13222. See PHI986. See PHI896. Harbormaster build targets don't currently have a modern "*.search" API, but there's no reason not to provide one (even if some of the use cases are a little bit questionable). Test Plan: {F6032423} Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13222 Differential Revision: https://secure.phabricator.com/D19841 --- src/__phutil_library_map__.php | 5 ++ .../HarbormasterTargetSearchAPIMethod.php | 18 ++++ .../HarbormasterBuildTargetSearchEngine.php | 73 ++++++++++++++++ .../storage/build/HarbormasterBuildTarget.php | 84 ++++++++++++++++++- 4 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 src/applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php create mode 100644 src/applications/harbormaster/query/HarbormasterBuildTargetSearchEngine.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e02178bc28..467a934211 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1353,6 +1353,7 @@ phutil_register_library_map(array( 'HarbormasterBuildTarget' => 'applications/harbormaster/storage/build/HarbormasterBuildTarget.php', 'HarbormasterBuildTargetPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildTargetPHIDType.php', 'HarbormasterBuildTargetQuery' => 'applications/harbormaster/query/HarbormasterBuildTargetQuery.php', + 'HarbormasterBuildTargetSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildTargetSearchEngine.php', 'HarbormasterBuildTransaction' => 'applications/harbormaster/storage/HarbormasterBuildTransaction.php', 'HarbormasterBuildTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php', 'HarbormasterBuildTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildTransactionQuery.php', @@ -1433,6 +1434,7 @@ phutil_register_library_map(array( 'HarbormasterStepEditController' => 'applications/harbormaster/controller/HarbormasterStepEditController.php', 'HarbormasterStepViewController' => 'applications/harbormaster/controller/HarbormasterStepViewController.php', 'HarbormasterTargetEngine' => 'applications/harbormaster/engine/HarbormasterTargetEngine.php', + 'HarbormasterTargetSearchAPIMethod' => 'applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php', 'HarbormasterTargetWorker' => 'applications/harbormaster/worker/HarbormasterTargetWorker.php', 'HarbormasterTestBuildStepGroup' => 'applications/harbormaster/stepgroup/HarbormasterTestBuildStepGroup.php', 'HarbormasterThrowExceptionBuildStep' => 'applications/harbormaster/step/HarbormasterThrowExceptionBuildStep.php', @@ -6832,9 +6834,11 @@ phutil_register_library_map(array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorConduitResultInterface', ), 'HarbormasterBuildTargetPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildTargetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'HarbormasterBuildTargetSearchEngine' => 'PhabricatorApplicationSearchEngine', 'HarbormasterBuildTransaction' => 'PhabricatorApplicationTransaction', 'HarbormasterBuildTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'HarbormasterBuildTransactionQuery' => 'PhabricatorApplicationTransactionQuery', @@ -6918,6 +6922,7 @@ phutil_register_library_map(array( 'HarbormasterStepEditController' => 'HarbormasterPlanController', 'HarbormasterStepViewController' => 'HarbormasterPlanController', 'HarbormasterTargetEngine' => 'Phobject', + 'HarbormasterTargetSearchAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'HarbormasterTargetWorker' => 'HarbormasterWorker', 'HarbormasterTestBuildStepGroup' => 'HarbormasterBuildStepGroup', 'HarbormasterThrowExceptionBuildStep' => 'HarbormasterBuildStepImplementation', diff --git a/src/applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php b/src/applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php new file mode 100644 index 0000000000..011ca2a47b --- /dev/null +++ b/src/applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php @@ -0,0 +1,18 @@ +setLabel(pht('Builds')) + ->setKey('buildPHIDs') + ->setAliases(array('build', 'builds', 'buildPHID')) + ->setDescription( + pht('Search for targets of a given build.')) + ->setDatasource(new HarbormasterBuildPlanDatasource()), + ); + } + + protected function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); + + if ($map['buildPHIDs']) { + $query->withBuildPHIDs($map['buildPHIDs']); + } + + return $query; + } + + protected function getURI($path) { + return '/harbormaster/target/'.$path; + } + + protected function getBuiltinQueryNames() { + return array( + 'all' => pht('All Targets'), + ); + } + + public function buildSavedQueryFromBuiltin($query_key) { + $query = $this->newSavedQuery(); + $query->setQueryKey($query_key); + + switch ($query_key) { + case 'all': + return $query; + } + + return parent::buildSavedQueryFromBuiltin($query_key); + } + + protected function renderResultList( + array $builds, + PhabricatorSavedQuery $query, + array $handles) { + assert_instances_of($builds, 'HarbormasterBuildTarget'); + + // Currently, this only supports the "harbormaster.target.search" + // API method. + throw new PhutilMethodNotImplementedException(); + } + +} diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php index b559a66198..30b1bd79e4 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php @@ -4,7 +4,8 @@ final class HarbormasterBuildTarget extends HarbormasterDAO implements PhabricatorPolicyInterface, - PhabricatorDestructibleInterface { + PhabricatorDestructibleInterface, + PhabricatorConduitResultInterface { protected $name; protected $buildPHID; @@ -412,4 +413,85 @@ final class HarbormasterBuildTarget } +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('name') + ->setType('string') + ->setDescription(pht('The name of the build target.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('buildPHID') + ->setType('phid') + ->setDescription(pht('The build the target is associated with.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('buildStepPHID') + ->setType('phid') + ->setDescription(pht('The build step the target runs.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('status') + ->setType('map') + ->setDescription(pht('Status for the build target.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('epochStarted') + ->setType('epoch?') + ->setDescription( + pht( + 'Epoch timestamp for target start, if the target '. + 'has started.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('epochCompleted') + ->setType('epoch?') + ->setDescription( + pht( + 'Epoch timestamp for target completion, if the target '. + 'has completed.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('buildGeneration') + ->setType('int') + ->setDescription( + pht( + 'Build generation this target belongs to. When builds '. + 'restart, a new generation with new targets is created.')), + ); + } + + public function getFieldValuesForConduit() { + $status = $this->getTargetStatus(); + + $epoch_started = $this->getDateStarted(); + if ($epoch_started) { + $epoch_started = (int)$epoch_started; + } else { + $epoch_started = null; + } + + $epoch_completed = $this->getDateCompleted(); + if ($epoch_completed) { + $epoch_completed = (int)$epoch_completed; + } else { + $epoch_completed = null; + } + + return array( + 'name' => $this->getName(), + 'buildPHID' => $this->getBuildPHID(), + 'buildStepPHID' => $this->getBuildStepPHID(), + 'status' => array( + 'value' => $status, + 'name' => self::getBuildTargetStatusName($status), + ), + 'epochStarted' => $epoch_started, + 'epochCompleted' => $epoch_completed, + 'buildGeneration' => (int)$this->getBuildGeneration(), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + + }