From aed755e1d88b3bb313fc227faaa50aff81ef1140 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 15 Apr 2019 06:36:17 -0700 Subject: [PATCH] Expose repository ref rules via "diffusion.repository.search" Summary: Depends on D20425. Ref T13277. See PHI1067. There's currently no way to retrieve branch/ref rules over the API, which makes some management operations against a large number of repositories difficult. Expose these rules to the API. Test Plan: Called `diffusion.repository.search`, got rules in the result set. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13277 Differential Revision: https://secure.phabricator.com/D20426 --- .../storage/PhabricatorRepository.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 928a7a1140..5fed41db83 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -2834,10 +2834,24 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO pht( 'The Almanac Service that hosts this repository, if the '. 'repository is clustered.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('refRules') + ->setType('map>') + ->setDescription( + pht( + 'The "Fetch" and "Permanent Ref" rules for this repository.')), ); } public function getFieldValuesForConduit() { + $fetch_rules = $this->getFetchRules(); + $track_rules = $this->getTrackOnlyRules(); + $permanent_rules = $this->getAutocloseOnlyRules(); + + $fetch_rules = $this->getStringListForConduit($fetch_rules); + $track_rules = $this->getStringListForConduit($track_rules); + $permanent_rules = $this->getStringListForConduit($permanent_rules); + return array( 'name' => $this->getName(), 'vcs' => $this->getVersionControlSystem(), @@ -2846,9 +2860,29 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO 'status' => $this->getStatus(), 'isImporting' => (bool)$this->isImporting(), 'almanacServicePHID' => $this->getAlmanacServicePHID(), + 'refRules' => array( + 'fetchRules' => $fetch_rules, + 'trackRules' => $track_rules, + 'permanentRefRules' => $permanent_rules, + ), ); } + private function getStringListForConduit($list) { + if (!is_array($list)) { + $list = array(); + } + + foreach ($list as $key => $value) { + $value = (string)$value; + if (!strlen($value)) { + unset($list[$key]); + } + } + + return array_values($list); + } + public function getConduitSearchAttachments() { return array( id(new DiffusionRepositoryURIsSearchEngineAttachment()) -- 2.51.2