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

Subsume 'harbormaster.querybuilds' with a modern search API method

Summary: We deprecate the existing API method used to access build information from the API, but preserve its response structure after calling through to the new method. I've cordoned off the fields I needed to define in order to meet the output structure by putting those fields in a search attachment.

Test Plan:
Used the API console and looked at the list view controller for builds.

Old output structure:

```lang=json
{
"data": [
{
"id": "16823",
"phid": "PHID-HMBD-xghrwfz6luoye5rgc2hq",
"uri": "https://secure.phabricator.com/harbormaster/build/16823/",
"name": "Run Core Tests",
"buildablePHID": "PHID-HMBB-s6ykzm2jzxz4ymduztq3",
"buildPlanPHID": "PHID-HMCP-pcfxcgyoif67l3buc4zt",
"buildStatus": "passed",
"buildStatusName": "Passed"
}
],
"cursor": {
"limit": 100,
"after": "16823",
"before": null
}
}
```

New output structure:

```lang=json
{
"data": [
{
"id": 1,
"type": "HMBD",
"phid": "PHID-HMBD-qpgcmv67tzaauzayzit5",
"uri": "http://ec2-54-165-244-168.compute-1.amazonaws.com/harbormaster/build/1/",
"name": "arc lint + arc unit",
"buildStatusName": "Passed",
"buildablePHID": "PHID-HMBB-qdefith5uakkepqpjr2g",
"buildPlanPHID": "PHID-HMCP-zswbhazb7ipmaf4plygg",
"buildStatus": "passed",
"initiatorPHID": "PHID-USER-rihx4366f3aczsvc2wtb",
"dateCreated": 1450295643,
"dateModified": 1450295644,
"policy": {
"view": "users",
"edit": "users"
}
}
],
"maps": {},
"query": {
"queryKey": null
},
"cursor": {
"limit": 100,
"after": null,
"before": null,
"order": null
}
}
```

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

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

authored by

Mike Riley and committed by
yelirekim
98492765 4865dbdf

+146 -55
+5
src/__phutil_library_map__.php
··· 1131 1131 'HarbormasterBuildPlanTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildPlanTransactionQuery.php', 1132 1132 'HarbormasterBuildQuery' => 'applications/harbormaster/query/HarbormasterBuildQuery.php', 1133 1133 'HarbormasterBuildRequest' => 'applications/harbormaster/engine/HarbormasterBuildRequest.php', 1134 + 'HarbormasterBuildSearchConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildSearchConduitAPIMethod.php', 1134 1135 'HarbormasterBuildSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildSearchEngine.php', 1135 1136 'HarbormasterBuildStatus' => 'applications/harbormaster/constants/HarbormasterBuildStatus.php', 1136 1137 'HarbormasterBuildStatusDatasource' => 'applications/harbormaster/typeahead/HarbormasterBuildStatusDatasource.php', ··· 1204 1205 'HarbormasterQueryAutotargetsConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterQueryAutotargetsConduitAPIMethod.php', 1205 1206 'HarbormasterQueryBuildablesConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterQueryBuildablesConduitAPIMethod.php', 1206 1207 'HarbormasterQueryBuildsConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php', 1208 + 'HarbormasterQueryBuildsSearchEngineAttachment' => 'applications/harbormaster/engineextension/HarbormasterQueryBuildsSearchEngineAttachment.php', 1207 1209 'HarbormasterRemarkupRule' => 'applications/harbormaster/remarkup/HarbormasterRemarkupRule.php', 1208 1210 'HarbormasterRunBuildPlansHeraldAction' => 'applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php', 1209 1211 'HarbormasterSchemaSpec' => 'applications/harbormaster/storage/HarbormasterSchemaSpec.php', ··· 5637 5639 'HarbormasterDAO', 5638 5640 'PhabricatorApplicationTransactionInterface', 5639 5641 'PhabricatorPolicyInterface', 5642 + 'PhabricatorConduitResultInterface', 5640 5643 ), 5641 5644 'HarbormasterBuildAbortedException' => 'Exception', 5642 5645 'HarbormasterBuildActionController' => 'HarbormasterController', ··· 5691 5694 'HarbormasterBuildPlanTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 5692 5695 'HarbormasterBuildQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5693 5696 'HarbormasterBuildRequest' => 'Phobject', 5697 + 'HarbormasterBuildSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 5694 5698 'HarbormasterBuildSearchEngine' => 'PhabricatorApplicationSearchEngine', 5695 5699 'HarbormasterBuildStatus' => 'Phobject', 5696 5700 'HarbormasterBuildStatusDatasource' => 'PhabricatorTypeaheadDatasource', ··· 5777 5781 'HarbormasterQueryAutotargetsConduitAPIMethod' => 'HarbormasterConduitAPIMethod', 5778 5782 'HarbormasterQueryBuildablesConduitAPIMethod' => 'HarbormasterConduitAPIMethod', 5779 5783 'HarbormasterQueryBuildsConduitAPIMethod' => 'HarbormasterConduitAPIMethod', 5784 + 'HarbormasterQueryBuildsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 5780 5785 'HarbormasterRemarkupRule' => 'PhabricatorObjectRemarkupRule', 5781 5786 'HarbormasterRunBuildPlansHeraldAction' => 'HeraldAction', 5782 5787 'HarbormasterSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+18
src/applications/harbormaster/conduit/HarbormasterBuildSearchConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildSearchConduitAPIMethod 4 + extends PhabricatorSearchEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'harbormaster.build.search'; 8 + } 9 + 10 + public function newSearchEngine() { 11 + return new HarbormasterBuildSearchEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht('Find out information about builds.'); 16 + } 17 + 18 + }
+36 -54
src/applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php
··· 11 11 return pht('Query Harbormaster builds.'); 12 12 } 13 13 14 + public function getMethodStatus() { 15 + return self::METHOD_STATUS_DEPRECATED; 16 + } 17 + 18 + public function getMethodStatusDescription() { 19 + return pht('Use %s instead.', 'harbormaster.build.search'); 20 + } 21 + 14 22 protected function defineParamTypes() { 15 23 return array( 16 24 'ids' => 'optional list<id>', ··· 27 35 28 36 protected function execute(ConduitAPIRequest $request) { 29 37 $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) { 38 + $call = new ConduitCall( 39 + 'harbormaster.build.search', 40 + array_filter(array( 41 + 'constraints' => array_filter(array( 42 + 'ids' => $request->getValue('ids'), 43 + 'phids' => $request->getValue('phids'), 44 + 'statuses' => $request->getValue('buildStatuses'), 45 + 'buildables' => $request->getValue('buildablePHIDs'), 46 + 'plans' => $request->getValue('buildPlanPHIDs'), 47 + )), 48 + 'attachments' => array( 49 + 'querybuilds' => true, 50 + ), 51 + 'limit' => $request->getValue('limit'), 52 + 'before' => $request->getValue('before'), 53 + 'after' => $request->getValue('after'), 54 + ))); 65 55 66 - $id = $build->getID(); 67 - $uri = '/harbormaster/build/'.$id.'/'; 68 - $status = $build->getBuildStatus(); 69 - $status_name = HarbormasterBuildStatus::getBuildStatusName($status); 56 + $subsumption = $call->setUser($viewer) 57 + ->execute(); 70 58 71 - $data[] = array( 72 - 'id' => $id, 73 - 'phid' => $build->getPHID(), 74 - 'uri' => PhabricatorEnv::getProductionURI($uri), 75 - 'name' => $build->getBuildPlan()->getName(), 76 - 'buildablePHID' => $build->getBuildablePHID(), 77 - 'buildPlanPHID' => $build->getBuildPlanPHID(), 78 - 'buildStatus' => $status, 79 - 'buildStatusName' => $status_name, 80 - ); 59 + $data = []; 60 + foreach ($subsumption['data'] as $build_data) { 61 + $querybuilds = idxv($build_data, array('attachments', 'querybuilds'), []); 62 + $fields = idx($build_data, 'fields', []); 63 + unset($build_data['fields']); 64 + unset($build_data['attachments']); 65 + $data[] = array_mergev(array($build_data, $querybuilds, $fields)); 81 66 } 82 67 83 - $results = array( 84 - 'data' => $data, 85 - ); 68 + $subsumption['data'] = $data; 86 69 87 - $results = $this->addPagerResults($results, $pager); 88 - return $results; 70 + return $subsumption; 89 71 } 90 72 91 73 }
+28
src/applications/harbormaster/engineextension/HarbormasterQueryBuildsSearchEngineAttachment.php
··· 1 + <?php 2 + 3 + final class HarbormasterQueryBuildsSearchEngineAttachment 4 + extends PhabricatorSearchEngineAttachment { 5 + 6 + public function getAttachmentName() { 7 + return pht('Harbormaster Query Builds'); 8 + } 9 + 10 + public function getAttachmentDescription() { 11 + return pht( 12 + 'This attachment exists solely to provide compatibility with the '. 13 + 'message format returned by an outdated API method. It will be '. 14 + 'taken away at some point and you should not rely on these fields '. 15 + 'being available.'); 16 + } 17 + 18 + public function getAttachmentForObject($object, $data, $spec) { 19 + $status_name = HarbormasterBuildStatus::getBuildStatusName( 20 + $object->getBuildStatus()); 21 + return array( 22 + 'uri' => PhabricatorEnv::getProductionURI($object->getURI()), 23 + 'name' => $object->getName(), 24 + 'buildStatusName' => $status_name, 25 + ); 26 + } 27 + 28 + }
+12
src/applications/harbormaster/query/HarbormasterBuildSearchEngine.php
··· 24 24 ->setDescription( 25 25 pht('Search for builds running a given build plan.')) 26 26 ->setDatasource(new HarbormasterBuildPlanDatasource()), 27 + id(new PhabricatorPHIDsSearchField()) 28 + ->setLabel(pht('Buildables')) 29 + ->setKey('buildables') 30 + ->setAliases(array('buildable')) 31 + ->setDescription( 32 + pht('Search for builds running against particular buildables.')), 27 33 id(new PhabricatorSearchDatasourceField()) 28 34 ->setLabel(pht('Statuses')) 29 35 ->setKey('statuses') ··· 39 45 pht( 40 46 'Search for builds started by someone or something in particular.')) 41 47 ->setDatasource(new HarbormasterBuildInitiatorDatasource()), 48 + ); 49 + } 50 + 51 + protected function getHiddenFields() { 52 + return array( 53 + 'buildables', 42 54 ); 43 55 } 44 56
+47 -1
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 3 3 final class HarbormasterBuild extends HarbormasterDAO 4 4 implements 5 5 PhabricatorApplicationTransactionInterface, 6 - PhabricatorPolicyInterface { 6 + PhabricatorPolicyInterface, 7 + PhabricatorConduitResultInterface { 7 8 8 9 protected $buildablePHID; 9 10 protected $buildPlanPHID; ··· 395 396 396 397 public function describeAutomaticCapability($capability) { 397 398 return pht('A build inherits policies from its buildable.'); 399 + } 400 + 401 + 402 + /* -( PhabricatorConduitResultInterface )---------------------------------- */ 403 + 404 + 405 + public function getFieldSpecificationsForConduit() { 406 + return array( 407 + id(new PhabricatorConduitSearchFieldSpecification()) 408 + ->setKey('buildablePHID') 409 + ->setType('phid') 410 + ->setDescription(pht('PHID of the object this build is building.')), 411 + id(new PhabricatorConduitSearchFieldSpecification()) 412 + ->setKey('buildPlanPHID') 413 + ->setType('phid') 414 + ->setDescription(pht('PHID of the build plan being run.')), 415 + id(new PhabricatorConduitSearchFieldSpecification()) 416 + ->setKey('buildStatus') 417 + ->setType('map<string, wild>') 418 + ->setDescription(pht('The current status of this build.')), 419 + id(new PhabricatorConduitSearchFieldSpecification()) 420 + ->setKey('initiatorPHID') 421 + ->setType('phid') 422 + ->setDescription(pht('The person (or thing) that started this build.')), 423 + ); 424 + } 425 + 426 + public function getFieldValuesForConduit() { 427 + $status = $this->getBuildStatus(); 428 + return array( 429 + 'buildablePHID' => $this->getBuildablePHID(), 430 + 'buildPlanPHID' => $this->getBuildPlanPHID(), 431 + 'buildStatus' => array( 432 + 'value' => $status, 433 + 'name' => HarbormasterBuildStatus::getBuildStatusName($status), 434 + ), 435 + 'initiatorPHID' => nonempty($this->getInitiatorPHID(), null), 436 + ); 437 + } 438 + 439 + public function getConduitSearchAttachments() { 440 + return array( 441 + id(new HarbormasterQueryBuildsSearchEngineAttachment()) 442 + ->setAttachmentKey('querybuilds'), 443 + ); 398 444 } 399 445 400 446 }