Skip to content

Commit 2ee4507

Browse files
dctrwatsonepriestley
authored andcommitted
Add Hosted/Remote filtering to Diffusion
Test Plan: Did searches in Diffusion using all 3 Hosted values Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Differential Revision: https://secure.phabricator.com/D7927
1 parent 5417f91 commit 2ee4507

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/applications/repository/query/PhabricatorRepositoryQuery.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ final class PhabricatorRepositoryQuery
2121
const ORDER_NAME = 'order-name';
2222
private $order = self::ORDER_CREATED;
2323

24+
const HOSTED_PHABRICATOR = 'hosted-phab';
25+
const HOSTED_REMOTE = 'hosted-remote';
26+
const HOSTED_ALL = 'hosted-all';
27+
private $hosted = self::HOSTED_ALL;
28+
2429
private $needMostRecentCommits;
2530
private $needCommitCounts;
2631
private $needProjectPHIDs;
@@ -45,6 +50,11 @@ public function withStatus($status) {
4550
return $this;
4651
}
4752

53+
public function withHosted($hosted) {
54+
$this->hosted = $hosted;
55+
return $this;
56+
}
57+
4858
public function withTypes(array $types) {
4959
$this->types = $types;
5060
return $this;
@@ -148,6 +158,24 @@ public function willFilterPage(array $repositories) {
148158
default:
149159
throw new Exception("Unknown status '{$status}'!");
150160
}
161+
162+
$hosted = $this->hosted;
163+
switch ($hosted) {
164+
case self::HOSTED_PHABRICATOR:
165+
if (!$repo->isHosted()) {
166+
unset($repositories[$key]);
167+
}
168+
break;
169+
case self::HOSTED_REMOTE:
170+
if ($repo->isHosted()) {
171+
unset($repositories[$key]);
172+
}
173+
break;
174+
case self::HOSTED_ALL:
175+
break;
176+
default:
177+
throw new Exception("Uknown hosted failed '${hosted}'!");
178+
}
151179
}
152180

153181
return $repositories;

src/applications/repository/query/PhabricatorRepositorySearchEngine.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public function buildSavedQueryFromRequest(AphrontRequest $request) {
99
$saved->setParameter('callsigns', $request->getStrList('callsigns'));
1010
$saved->setParameter('status', $request->getStr('status'));
1111
$saved->setParameter('order', $request->getStr('order'));
12+
$saved->setParameter('hosted', $request->getStr('hosted'));
1213
$saved->setParameter('types', $request->getArr('types'));
1314
$saved->setParameter('name', $request->getStr('name'));
1415

@@ -40,6 +41,12 @@ public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
4041
$query->setOrder(head($this->getOrderValues()));
4142
}
4243

44+
$hosted = $saved->getParameter('hosted');
45+
$hosted = idx($this->getHostedValues(), $hosted);
46+
if ($hosted) {
47+
$query->withHosted($hosted);
48+
}
49+
4350
$types = $saved->getParameter('types');
4451
if ($types) {
4552
$query->withTypes($types);
@@ -78,7 +85,13 @@ public function buildSearchForm(
7885
->setName('status')
7986
->setLabel(pht('Status'))
8087
->setValue($saved_query->getParameter('status'))
81-
->setOptions($this->getStatusOptions()));
88+
->setOptions($this->getStatusOptions()))
89+
->appendChild(
90+
id(new AphrontFormSelectControl())
91+
->setName('hosted')
92+
->setLabel(pht('Hosted'))
93+
->setValue($saved_query->getParameter('hosted'))
94+
->setOptions($this->getHostedOptions()));
8295

8396
$type_control = id(new AphrontFormCheckboxControl())
8497
->setLabel(pht('Types'));
@@ -164,5 +177,20 @@ private function getOrderValues() {
164177
);
165178
}
166179

180+
private function getHostedOptions() {
181+
return array(
182+
'' => pht('Hosted and Remote Repositories'),
183+
'phabricator' => pht('Hosted Repositories'),
184+
'remote' => pht('Remote Repositories'),
185+
);
186+
}
187+
188+
private function getHostedValues() {
189+
return array(
190+
'' => PhabricatorRepositoryQuery::HOSTED_ALL,
191+
'phabricator' => PhabricatorRepositoryQuery::HOSTED_PHABRICATOR,
192+
'remote' => PhabricatorRepositoryQuery::HOSTED_REMOTE,
193+
);
194+
}
167195

168196
}

0 commit comments

Comments
 (0)