diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1338,6 +1338,8 @@ 'HarbormasterArcLintBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterArcLintBuildStepImplementation.php', 'HarbormasterArcUnitBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterArcUnitBuildStepImplementation.php', 'HarbormasterArtifact' => 'applications/harbormaster/artifact/HarbormasterArtifact.php', + 'HarbormasterArtifactSearchConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterArtifactSearchConduitAPIMethod.php', + 'HarbormasterArtifactSearchEngine' => 'applications/harbormaster/query/HarbormasterArtifactSearchEngine.php', 'HarbormasterAutotargetsTestCase' => 'applications/harbormaster/__tests__/HarbormasterAutotargetsTestCase.php', 'HarbormasterBuild' => 'applications/harbormaster/storage/build/HarbormasterBuild.php', 'HarbormasterBuildAbortedException' => 'applications/harbormaster/exception/HarbormasterBuildAbortedException.php', @@ -7369,6 +7371,8 @@ 'HarbormasterArcLintBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 'HarbormasterArcUnitBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 'HarbormasterArtifact' => 'Phobject', + 'HarbormasterArtifactSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', + 'HarbormasterArtifactSearchEngine' => 'PhabricatorApplicationSearchEngine', 'HarbormasterAutotargetsTestCase' => 'PhabricatorTestCase', 'HarbormasterBuild' => array( 'HarbormasterDAO', @@ -7384,6 +7388,7 @@ 'HarbormasterDAO', 'PhabricatorPolicyInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorConduitResultInterface', ), 'HarbormasterBuildArtifactPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildArtifactQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/harbormaster/conduit/HarbormasterArtifactSearchConduitAPIMethod.php b/src/applications/harbormaster/conduit/HarbormasterArtifactSearchConduitAPIMethod.php new file mode 100644 --- /dev/null +++ b/src/applications/harbormaster/conduit/HarbormasterArtifactSearchConduitAPIMethod.php @@ -0,0 +1,18 @@ +setLabel(pht('Targets')) + ->setKey('buildTargetPHIDs') + ->setAliases( + array( + 'buildTargetPHID', + 'buildTargets', + 'buildTarget', + 'targetPHIDs', + 'targetPHID', + 'targets', + 'target', + )) + ->setDescription( + pht('Search for artifacts attached to particular build targets.')), + ); + } + + protected function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); + + if ($map['buildTargetPHIDs']) { + $query->withBuildTargetPHIDs($map['buildTargetPHIDs']); + } + + return $query; + } + + protected function getURI($path) { + return '/harbormaster/artifact/'.$path; + } + + protected function getBuiltinQueryNames() { + return array( + 'all' => pht('All Artifacts'), + ); + } + + 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 $artifacts, + PhabricatorSavedQuery $query, + array $handles) { + assert_instances_of($artifacts, 'HarbormasterBuildArtifact'); + + $viewer = $this->requireViewer(); + + $list = new PHUIObjectItemListView(); + foreach ($artifacts as $artifact) { + $id = $artifact->getID(); + + $item = id(new PHUIObjectItemView()) + ->setObjectName(pht('Artifact %d', $id)); + + $list->addItem($item); + } + + return id(new PhabricatorApplicationSearchResultView()) + ->setObjectList($list) + ->setNoDataString(pht('No artifacts found.')); + } + +} diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php b/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php --- a/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php @@ -4,7 +4,8 @@ extends HarbormasterDAO implements PhabricatorPolicyInterface, - PhabricatorDestructibleInterface { + PhabricatorDestructibleInterface, + PhabricatorConduitResultInterface { protected $buildTargetPHID; protected $artifactType; @@ -18,6 +19,7 @@ public static function initializeNewBuildArtifact( HarbormasterBuildTarget $build_target) { + return id(new HarbormasterBuildArtifact()) ->attachBuildTarget($build_target) ->setBuildTargetPHID($build_target->getPHID()); @@ -53,9 +55,8 @@ ) + parent::getConfiguration(); } - public function generatePHID() { - return PhabricatorPHID::generateNewPHID( - HarbormasterBuildArtifactPHIDType::TYPECONST); + public function getPHIDType() { + return HarbormasterBuildArtifactPHIDType::TYPECONST; } public function attachBuildTarget(HarbormasterBuildTarget $build_target) { @@ -147,7 +148,8 @@ } public function describeAutomaticCapability($capability) { - return pht('Users must be able to see a buildable to see its artifacts.'); + return pht( + 'Users must be able to see a build target to see its artifacts.'); } @@ -165,4 +167,40 @@ $this->saveTransaction(); } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('buildTargetPHID') + ->setType('phid') + ->setDescription(pht('The build target this artifact is attached to.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('artifactType') + ->setType('string') + ->setDescription(pht('The artifact type.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('artifactKey') + ->setType('string') + ->setDescription(pht('The artifact key.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('isReleased') + ->setType('bool') + ->setDescription(pht('True if this artifact has been released.')), + ); + } + + public function getFieldValuesForConduit() { + return array( + 'buildTargetPHID' => $this->getBuildTargetPHID(), + 'artifactType' => $this->getArtifactType(), + 'artifactKey' => $this->getArtifactKey(), + 'isReleased' => (bool)$this->getIsReleased(), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } }