2014-04-27 18:43:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCommitSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Commits');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
|
|
|
return 'PhabricatorDiffusionApplication';
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'auditorPHIDs',
|
|
|
|
$this->readPHIDsFromRequest($request, 'auditorPHIDs'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'commitAuthorPHIDs',
|
2014-05-02 17:56:16 +02:00
|
|
|
$this->readUsersFromRequest($request, 'authors'));
|
2014-04-27 18:43:05 +02:00
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'auditStatus',
|
|
|
|
$request->getStr('auditStatus'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'repositoryPHIDs',
|
|
|
|
$this->readPHIDsFromRequest($request, 'repositoryPHIDs'));
|
|
|
|
|
|
|
|
// -- TODO - T4173 - file location
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new DiffusionCommitQuery())
|
|
|
|
->needAuditRequests(true)
|
|
|
|
->needCommitData(true);
|
|
|
|
|
|
|
|
$auditor_phids = $saved->getParameter('auditorPHIDs', array());
|
|
|
|
if ($auditor_phids) {
|
|
|
|
$query->withAuditorPHIDs($auditor_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$commit_author_phids = $saved->getParameter('commitAuthorPHIDs', array());
|
|
|
|
if ($commit_author_phids) {
|
|
|
|
$query->withAuthorPHIDs($commit_author_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$audit_status = $saved->getParameter('auditStatus', null);
|
|
|
|
if ($audit_status) {
|
|
|
|
$query->withAuditStatus($audit_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
$awaiting_user_phid = $saved->getParameter('awaitingUserPHID', null);
|
|
|
|
if ($awaiting_user_phid) {
|
|
|
|
// This is used only for the built-in "needs attention" filter,
|
|
|
|
// so cheat and just use the already-loaded viewer rather than reloading
|
|
|
|
// it.
|
|
|
|
$query->withAuditAwaitingUser($this->requireViewer());
|
|
|
|
}
|
|
|
|
|
2014-08-14 21:40:47 +02:00
|
|
|
$repository_phids = $saved->getParameter('repositoryPHIDs', array());
|
|
|
|
if ($repository_phids) {
|
|
|
|
$query->withRepositoryPHIDs($repository_phids);
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved) {
|
|
|
|
|
|
|
|
$auditor_phids = $saved->getParameter('auditorPHIDs', array());
|
|
|
|
$commit_author_phids = $saved->getParameter(
|
|
|
|
'commitAuthorPHIDs',
|
|
|
|
array());
|
|
|
|
$audit_status = $saved->getParameter('auditStatus', null);
|
2014-08-14 21:40:47 +02:00
|
|
|
$repository_phids = $saved->getParameter('repositoryPHIDs', array());
|
2014-04-27 18:43:05 +02:00
|
|
|
|
|
|
|
$phids = array_mergev(
|
|
|
|
array(
|
|
|
|
$auditor_phids,
|
2014-08-14 21:40:47 +02:00
|
|
|
$commit_author_phids,
|
2014-10-07 15:01:04 +02:00
|
|
|
$repository_phids,
|
|
|
|
));
|
2014-04-27 18:43:05 +02:00
|
|
|
|
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($this->requireViewer())
|
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:45:21 +02:00
|
|
|
->setDatasource(new DiffusionAuditorDatasource())
|
2014-04-27 18:43:05 +02:00
|
|
|
->setName('auditorPHIDs')
|
|
|
|
->setLabel(pht('Auditors'))
|
|
|
|
->setValue(array_select_keys($handles, $auditor_phids)))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2014-05-02 17:56:16 +02:00
|
|
|
->setName('authors')
|
2014-04-27 18:43:05 +02:00
|
|
|
->setLabel(pht('Commit Authors'))
|
|
|
|
->setValue(array_select_keys($handles, $commit_author_phids)))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setName('auditStatus')
|
|
|
|
->setLabel(pht('Audit Status'))
|
|
|
|
->setOptions($this->getAuditStatusOptions())
|
2014-08-14 21:40:47 +02:00
|
|
|
->setValue($audit_status))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setLabel(pht('Repositories'))
|
|
|
|
->setName('repositoryPHIDs')
|
|
|
|
->setDatasource(new DiffusionRepositoryDatasource())
|
|
|
|
->setValue(array_select_keys($handles, $repository_phids)));
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/audit/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-04-27 18:43:05 +02:00
|
|
|
$names = array();
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
2014-04-28 17:26:08 +02:00
|
|
|
$names['need'] = pht('Need Attention');
|
|
|
|
$names['problem'] = pht('Problem Commits');
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|
2014-04-28 17:26:08 +02:00
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
$names['open'] = pht('Open Audits');
|
|
|
|
|
2014-05-13 17:06:22 +02:00
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
$names['authored'] = pht('Authored Commits');
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
$names['all'] = pht('All Commits');
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
case 'open':
|
|
|
|
$query->setParameter(
|
|
|
|
'auditStatus',
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_OPEN);
|
|
|
|
return $query;
|
2014-04-28 17:26:08 +02:00
|
|
|
case 'need':
|
2014-04-27 18:43:05 +02:00
|
|
|
$query->setParameter('awaitingUserPHID', $viewer->getPHID());
|
|
|
|
$query->setParameter(
|
|
|
|
'auditStatus',
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_OPEN);
|
|
|
|
$query->setParameter(
|
|
|
|
'auditorPHIDs',
|
|
|
|
PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($viewer));
|
|
|
|
return $query;
|
2014-05-13 17:06:22 +02:00
|
|
|
case 'authored':
|
|
|
|
$query->setParameter('commitAuthorPHIDs', array($viewer->getPHID()));
|
|
|
|
return $query;
|
2014-04-28 17:26:08 +02:00
|
|
|
case 'problem':
|
|
|
|
$query->setParameter('commitAuthorPHIDs', array($viewer->getPHID()));
|
|
|
|
$query->setParameter(
|
|
|
|
'auditStatus',
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_CONCERN);
|
|
|
|
return $query;
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAuditStatusOptions() {
|
|
|
|
return array(
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_ANY => pht('Any'),
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_OPEN => pht('Open'),
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_CONCERN => pht('Concern Raised'),
|
2014-08-19 19:43:52 +02:00
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_ACCEPTED => pht('Accepted'),
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_PARTIAL => pht('Partially Audited'),
|
2014-04-27 18:43:05 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-05-08 17:49:32 +02:00
|
|
|
protected function renderResultList(
|
|
|
|
array $commits,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
|
|
|
|
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
$nodata = pht('No matching audits.');
|
|
|
|
$view = id(new PhabricatorAuditListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setCommits($commits)
|
|
|
|
->setAuthorityPHIDs(
|
|
|
|
PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($viewer))
|
|
|
|
->setNoDataString($nodata);
|
|
|
|
|
|
|
|
$phids = $view->getRequiredHandlePHIDs();
|
|
|
|
if ($phids) {
|
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
} else {
|
|
|
|
$handles = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->setHandles($handles);
|
|
|
|
|
|
|
|
return $view->buildList();
|
|
|
|
}
|
|
|
|
|
2014-04-27 18:43:05 +02:00
|
|
|
}
|