Differential D16096 Diff 38755 src/applications/diffusion/typeahead/DiffusionTaggedRepositoriesFunctionDatasource.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/typeahead/DiffusionTaggedRepositoriesFunctionDatasource.php
- This file was added.
<?php | |||||
final class DiffusionTaggedRepositoriesFunctionDatasource | |||||
extends PhabricatorTypeaheadCompositeDatasource { | |||||
public function getBrowseTitle() { | |||||
return pht('Browse Repositories'); | |||||
} | |||||
public function getPlaceholderText() { | |||||
return pht('Type tagged(<project>)...'); | |||||
} | |||||
public function getDatasourceApplicationClass() { | |||||
return 'PhabricatorProjectApplication'; | |||||
} | |||||
public function getComponentDatasources() { | |||||
return array( | |||||
new PhabricatorProjectDatasource(), | |||||
); | |||||
} | |||||
public function getDatasourceFunctions() { | |||||
return array( | |||||
'tagged' => array( | |||||
'name' => pht('Repositories: ...'), | |||||
epriestley: This should be `'tagged'`. | |||||
'arguments' => pht('project'), | |||||
'summary' => pht('Find results for repositories of a project.'), | |||||
'description' => pht( | |||||
'This function allows you to find results for any of the `. | |||||
`repositories of a project:'. | |||||
"\n\n". | |||||
'> tagged(engineering)'), | |||||
), | |||||
Done Inline ActionsThis should have a usage example, like: > tagged(engineering) epriestley: This should have a usage example, like:
```
> tagged(engineering)
``` | |||||
); | |||||
} | |||||
protected function didLoadResults(array $results) { | |||||
foreach ($results as $result) { | |||||
$result | |||||
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) | |||||
->setColor(null) | |||||
->setPHID('tagged('.$result->getPHID().')') | |||||
->setDisplayName(pht('Tagged: %s', $result->getDisplayName())) | |||||
Done Inline ActionsThis should be tagged(...). epriestley: This should be `tagged(...)`. | |||||
->setName('tagged '.$result->getName()); | |||||
Done Inline ActionsPrefer "Tagged" (with capital letter) over "tagged" (no capital letter) for consistency with other function datasources. epriestley: Prefer "Tagged" (with capital letter) over "tagged" (no capital letter) for consistency with… | |||||
} | |||||
Done Inline Actionsepriestley: This is very minor, but prefer putting the function name (`'tagged '.`) first instead of last. | |||||
return $results; | |||||
} | |||||
protected function evaluateFunction($function, array $argv_list) { | |||||
$phids = array(); | |||||
foreach ($argv_list as $argv) { | |||||
$phids[] = head($argv); | |||||
} | |||||
$repositories = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withEdgeLogicPHIDs( | |||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
PhabricatorQueryConstraint::OPERATOR_OR, | |||||
$phids) | |||||
->execute(); | |||||
Done Inline ActionsThis block should only be indented one level. (We should ideally get lint to fix this automatically, but it's tricky.) epriestley: This block should only be indented one level.
(We should ideally get lint to fix this… | |||||
$results = array(); | |||||
foreach ($repositories as $repository) { | |||||
$results[] = $repository->getPHID(); | |||||
} | |||||
return $results; | |||||
} | |||||
public function renderFunctionTokens($function, array $argv_list) { | |||||
$phids = array(); | |||||
foreach ($argv_list as $argv) { | |||||
$phids[] = head($argv); | |||||
} | |||||
$tokens = $this->renderTokens($phids); | |||||
foreach ($tokens as $token) { | |||||
// Remove any project color on this token. | |||||
$token->setColor(null); | |||||
if ($token->isInvalid()) { | |||||
$token | |||||
->setValue(pht('Repositories: Invalid Project')); | |||||
} else { | |||||
$token | |||||
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) | |||||
->setKey('tagged('.$token->getKey().')') | |||||
->setValue(pht('Tagged: %s', $token->getValue())); | |||||
} | |||||
Done Inline ActionsShould be tagged( and "Tagged" for consistency with above. epriestley: Should be `tagged(` and `"Tagged"` for consistency with above. | |||||
} | |||||
return $tokens; | |||||
} | |||||
} |
This should be 'tagged'.