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

Provide API read access to Harbormaster build logs

Summary:
Depends on D19150. Ref T13088. Allow clients to retrieve information about build logs, including log data, over the API.

(To fetch log data, take the `filePHID` to `file.search`, then issue a normal GET against the URI. Use a `Content-Range` header to get part of the log.)

Test Plan: Ran `harbormaster.log.search`, got sensible-looking results.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

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

+151 -25
+5
src/__phutil_library_map__.php
··· 1235 1235 'HarbormasterBuildLogPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php', 1236 1236 'HarbormasterBuildLogQuery' => 'applications/harbormaster/query/HarbormasterBuildLogQuery.php', 1237 1237 'HarbormasterBuildLogRenderController' => 'applications/harbormaster/controller/HarbormasterBuildLogRenderController.php', 1238 + 'HarbormasterBuildLogSearchConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildLogSearchConduitAPIMethod.php', 1239 + 'HarbormasterBuildLogSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildLogSearchEngine.php', 1238 1240 'HarbormasterBuildLogTestCase' => 'applications/harbormaster/__tests__/HarbormasterBuildLogTestCase.php', 1239 1241 'HarbormasterBuildLogView' => 'applications/harbormaster/view/HarbormasterBuildLogView.php', 1240 1242 'HarbormasterBuildLogViewController' => 'applications/harbormaster/controller/HarbormasterBuildLogViewController.php', ··· 6522 6524 'HarbormasterDAO', 6523 6525 'PhabricatorPolicyInterface', 6524 6526 'PhabricatorDestructibleInterface', 6527 + 'PhabricatorConduitResultInterface', 6525 6528 ), 6526 6529 'HarbormasterBuildLogChunk' => 'HarbormasterDAO', 6527 6530 'HarbormasterBuildLogChunkIterator' => 'PhutilBufferedIterator', ··· 6529 6532 'HarbormasterBuildLogPHIDType' => 'PhabricatorPHIDType', 6530 6533 'HarbormasterBuildLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6531 6534 'HarbormasterBuildLogRenderController' => 'HarbormasterController', 6535 + 'HarbormasterBuildLogSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 6536 + 'HarbormasterBuildLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 6532 6537 'HarbormasterBuildLogTestCase' => 'PhabricatorTestCase', 6533 6538 'HarbormasterBuildLogView' => 'AphrontView', 6534 6539 'HarbormasterBuildLogViewController' => 'HarbormasterController',
+18
src/applications/harbormaster/conduit/HarbormasterBuildLogSearchConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildLogSearchConduitAPIMethod 4 + extends PhabricatorSearchEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'harbormaster.log.search'; 8 + } 9 + 10 + public function newSearchEngine() { 11 + return new HarbormasterBuildLogSearchEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht('Find out information about build logs.'); 16 + } 17 + 18 + }
+14 -23
src/applications/harbormaster/query/HarbormasterBuildLogQuery.php
··· 23 23 return $this; 24 24 } 25 25 26 + public function newResultObject() { 27 + return new HarbormasterBuildLog(); 28 + } 29 + 26 30 protected function loadPage() { 27 - $table = new HarbormasterBuildLog(); 28 - $conn_r = $table->establishConnection('r'); 29 - 30 - $data = queryfx_all( 31 - $conn_r, 32 - 'SELECT * FROM %T %Q %Q %Q', 33 - $table->getTableName(), 34 - $this->buildWhereClause($conn_r), 35 - $this->buildOrderClause($conn_r), 36 - $this->buildLimitClause($conn_r)); 37 - 38 - return $table->loadAllFromArray($data); 31 + return $this->loadStandardPage($this->newResultObject()); 39 32 } 40 33 41 34 protected function willFilterPage(array $page) { ··· 63 56 return $page; 64 57 } 65 58 66 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 67 - $where = array(); 59 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 60 + $where = parent::buildWhereClauseParts($conn); 68 61 69 - if ($this->ids) { 62 + if ($this->ids !== null) { 70 63 $where[] = qsprintf( 71 - $conn_r, 64 + $conn, 72 65 'id IN (%Ld)', 73 66 $this->ids); 74 67 } 75 68 76 - if ($this->phids) { 69 + if ($this->phids !== null) { 77 70 $where[] = qsprintf( 78 - $conn_r, 71 + $conn, 79 72 'phid IN (%Ls)', 80 73 $this->phids); 81 74 } 82 75 83 - if ($this->buildTargetPHIDs) { 76 + if ($this->buildTargetPHIDs !== null) { 84 77 $where[] = qsprintf( 85 - $conn_r, 78 + $conn, 86 79 'buildTargetPHID IN (%Ls)', 87 80 $this->buildTargetPHIDs); 88 81 } 89 82 90 - $where[] = $this->buildPagingClause($conn_r); 91 - 92 - return $this->formatWhereClause($where); 83 + return $where; 93 84 } 94 85 95 86 public function getQueryApplicationClass() {
+79
src/applications/harbormaster/query/HarbormasterBuildLogSearchEngine.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildLogSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Harbormaster Build Logs'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return 'PhabricatorHarbormasterApplication'; 12 + } 13 + 14 + public function newQuery() { 15 + return new HarbormasterBuildLogQuery(); 16 + } 17 + 18 + protected function buildCustomSearchFields() { 19 + return array( 20 + id(new PhabricatorPHIDsSearchField()) 21 + ->setLabel(pht('Build Targets')) 22 + ->setKey('buildTargetPHIDs') 23 + ->setAliases( 24 + array( 25 + 'buildTargetPHID', 26 + 'buildTargets', 27 + 'buildTarget', 28 + 'targetPHIDs', 29 + 'targetPHID', 30 + 'targets', 31 + 'target', 32 + )) 33 + ->setDescription( 34 + pht('Search for logs that belong to a particular build target.')), 35 + ); 36 + } 37 + 38 + protected function buildQueryFromParameters(array $map) { 39 + $query = $this->newQuery(); 40 + 41 + if ($map['buildTargetPHIDs']) { 42 + $query->withBuildTargetPHIDs($map['buildTargetPHIDs']); 43 + } 44 + 45 + return $query; 46 + } 47 + 48 + protected function getURI($path) { 49 + return '/harbormaster/log/'.$path; 50 + } 51 + 52 + protected function getBuiltinQueryNames() { 53 + return array( 54 + 'all' => pht('All Builds'), 55 + ); 56 + } 57 + 58 + public function buildSavedQueryFromBuiltin($query_key) { 59 + $query = $this->newSavedQuery(); 60 + $query->setQueryKey($query_key); 61 + 62 + switch ($query_key) { 63 + case 'all': 64 + return $query; 65 + } 66 + 67 + return parent::buildSavedQueryFromBuiltin($query_key); 68 + } 69 + 70 + protected function renderResultList( 71 + array $builds, 72 + PhabricatorSavedQuery $query, 73 + array $handles) { 74 + 75 + // For now, this SearchEngine is only for driving the API. 76 + throw new PhutilMethodNotImplementedException(); 77 + } 78 + 79 + }
+34 -1
src/applications/harbormaster/storage/build/HarbormasterBuildLog.php
··· 4 4 extends HarbormasterDAO 5 5 implements 6 6 PhabricatorPolicyInterface, 7 - PhabricatorDestructibleInterface { 7 + PhabricatorDestructibleInterface, 8 + PhabricatorConduitResultInterface { 8 9 9 10 protected $buildTargetPHID; 10 11 protected $logSource; ··· 713 714 return $this; 714 715 } 715 716 717 + 718 + /* -( PhabricatorConduitResultInterface )---------------------------------- */ 719 + 720 + 721 + public function getFieldSpecificationsForConduit() { 722 + return array( 723 + id(new PhabricatorConduitSearchFieldSpecification()) 724 + ->setKey('buildTargetPHID') 725 + ->setType('phid') 726 + ->setDescription(pht('Build target this log is attached to.')), 727 + id(new PhabricatorConduitSearchFieldSpecification()) 728 + ->setKey('byteLength') 729 + ->setType('int') 730 + ->setDescription(pht('Length of the log in bytes.')), 731 + id(new PhabricatorConduitSearchFieldSpecification()) 732 + ->setKey('filePHID') 733 + ->setType('phid?') 734 + ->setDescription(pht('A file containing the log data.')), 735 + ); 736 + } 737 + 738 + public function getFieldValuesForConduit() { 739 + return array( 740 + 'buildTargetPHID' => $this->getBuildTargetPHID(), 741 + 'byteLength' => (int)$this->getByteLength(), 742 + 'filePHID' => $this->getFilePHID(), 743 + ); 744 + } 745 + 746 + public function getConduitSearchAttachments() { 747 + return array(); 748 + } 716 749 717 750 }
+1 -1
src/view/control/AphrontTableView.php
··· 248 248 249 249 foreach ($col_classes as $key => $value) { 250 250 251 - if (($sort_values[$key] !== null) && 251 + if (isset($sort_values[$key]) && 252 252 ($sort_values[$key] == $this->sortSelected)) { 253 253 $value = trim($value.' sorted-column'); 254 254 }