Allow commits to be queried by repository using the tagged(...) typehaead function

Summary:
Fixes T12322. Allows you to search for commits using the `tagged(...)` repository function, so you can find "any commmit in any repository tagged with android" or similar.

I moved the function from Differential (which was the application using it) to Diffusion (which is more accurately the application which provides it).

I fixed a bug where searching for `tagged(xyz)` would have no effect (constraint was ignored) if there were no repositories tagged with "xyz". The fix isn't perfectly clean, but should work properly for the moment.

Test Plan:
  - Searched with `tagged(...)` in Diffusion and Differential.
  - Searched by repository.
  - Searched with `tagged(...)` for a project with no tagged repositories.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12322

Differential Revision: https://secure.phabricator.com/D17426
This commit is contained in:
epriestley
2017-02-27 10:21:23 -08:00
parent 3bea3fbb12
commit c5fa7421c2
5 changed files with 14 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
<?php
final class DiffusionRepositoryFunctionDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getBrowseTitle() {
return pht('Browse Repositories');
}
public function getPlaceholderText() {
return pht('Type a repository name or function...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorDifferentialApplication';
}
public function getComponentDatasources() {
return array(
new DiffusionTaggedRepositoriesFunctionDatasource(),
new DiffusionRepositoryDatasource(),
);
}
}

View File

@@ -67,11 +67,19 @@ final class DiffusionTaggedRepositoriesFunctionDatasource
->execute();
$results = array();
foreach ($repositories as $repository) {
$results[] = $repository->getPHID();
}
if (!$results) {
// TODO: This is a little hacky, but if you query for "tagged(x)" and
// there are no such repositories, we want to match nothing. If we
// just return `array()`, that gets evaluated as "no constraint" and
// we match everything. This works correctly for now, but should be
// replaced with some more elegant/general approach eventually.
$results[] = PhabricatorPHIDConstants::PHID_VOID;
}
return $results;
}