2014-04-27 09:43:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorCommitSearchEngine
|
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
2014-06-12 13:22:20 -07:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
|
return pht('Commits');
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 15:47:48 -08:00
|
|
|
public function getApplicationClassName() {
|
|
|
|
|
return 'PhabricatorDiffusionApplication';
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
public function newQuery() {
|
|
|
|
|
return id(new DiffusionCommitQuery())
|
2014-04-27 09:43:05 -07:00
|
|
|
->needAuditRequests(true)
|
|
|
|
|
->needCommitData(true);
|
2015-08-31 10:17:54 -07:00
|
|
|
}
|
2014-04-27 09:43:05 -07:00
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
protected function buildQueryFromParameters(array $map) {
|
|
|
|
|
$query = $this->newQuery();
|
|
|
|
|
|
|
|
|
|
if ($map['needsAuditByPHIDs']) {
|
|
|
|
|
$query->withNeedsAuditByPHIDs($map['needsAuditByPHIDs']);
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
if ($map['auditorPHIDs']) {
|
|
|
|
|
$query->withAuditorPHIDs($map['auditorPHIDs']);
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
if ($map['commitAuthorPHIDs']) {
|
|
|
|
|
$query->withAuthorPHIDs($map['commitAuthorPHIDs']);
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
if ($map['auditStatus']) {
|
|
|
|
|
$query->withAuditStatus($map['auditStatus']);
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
if ($map['repositoryPHIDs']) {
|
|
|
|
|
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
|
2014-08-14 12:40:47 -07:00
|
|
|
}
|
|
|
|
|
|
2014-04-27 09:43:05 -07:00
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
protected function buildCustomSearchFields() {
|
|
|
|
|
return array(
|
|
|
|
|
id(new PhabricatorSearchDatasourceField())
|
|
|
|
|
->setLabel(pht('Needs Audit By'))
|
|
|
|
|
->setKey('needsAuditByPHIDs')
|
|
|
|
|
->setAliases(array('needs', 'need'))
|
|
|
|
|
->setDatasource(new DiffusionAuditorFunctionDatasource()),
|
|
|
|
|
id(new PhabricatorSearchDatasourceField())
|
|
|
|
|
->setLabel(pht('Auditors'))
|
|
|
|
|
->setKey('auditorPHIDs')
|
|
|
|
|
->setAliases(array('auditor', 'auditors'))
|
|
|
|
|
->setDatasource(new DiffusionAuditorFunctionDatasource()),
|
|
|
|
|
id(new PhabricatorUsersSearchField())
|
|
|
|
|
->setLabel(pht('Authors'))
|
|
|
|
|
->setKey('commitAuthorPHIDs')
|
|
|
|
|
->setAliases(array('author', 'authors')),
|
|
|
|
|
id(new PhabricatorSearchSelectField())
|
|
|
|
|
->setLabel(pht('Audit Status'))
|
|
|
|
|
->setKey('auditStatus')
|
|
|
|
|
->setAliases(array('status'))
|
|
|
|
|
->setOptions($this->getAuditStatusOptions()),
|
|
|
|
|
id(new PhabricatorSearchDatasourceField())
|
|
|
|
|
->setLabel(pht('Repositories'))
|
|
|
|
|
->setKey('repositoryPHIDs')
|
|
|
|
|
->setAliases(array('repository', 'repositories'))
|
|
|
|
|
->setDatasource(new DiffusionRepositoryDatasource()),
|
|
|
|
|
);
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
|
return '/audit/'.$path;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 07:34:51 +11:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-04-27 09:43:05 -07:00
|
|
|
$names = array();
|
|
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
2015-08-31 10:17:54 -07:00
|
|
|
$names['need'] = pht('Needs Audit');
|
2014-04-28 08:26:08 -07:00
|
|
|
$names['problem'] = pht('Problem Commits');
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|
2014-04-28 08:26:08 -07:00
|
|
|
|
2014-04-27 09:43:05 -07:00
|
|
|
$names['open'] = pht('Open Audits');
|
|
|
|
|
|
2014-05-13 08:06:22 -07:00
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
|
$names['authored'] = pht('Authored Commits');
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 09:43:05 -07:00
|
|
|
$names['all'] = pht('All Commits');
|
|
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
2015-08-31 10:17:54 -07:00
|
|
|
$viewer_phid = $viewer->getPHID();
|
|
|
|
|
$status_open = DiffusionCommitQuery::AUDIT_STATUS_OPEN;
|
|
|
|
|
|
2014-04-27 09:43:05 -07:00
|
|
|
switch ($query_key) {
|
|
|
|
|
case 'all':
|
|
|
|
|
return $query;
|
|
|
|
|
case 'open':
|
2015-08-31 10:17:54 -07:00
|
|
|
$query->setParameter('auditStatus', $status_open);
|
2014-04-27 09:43:05 -07:00
|
|
|
return $query;
|
2014-04-28 08:26:08 -07:00
|
|
|
case 'need':
|
2015-08-31 10:17:54 -07:00
|
|
|
$needs_tokens = array(
|
|
|
|
|
$viewer_phid,
|
|
|
|
|
'projects('.$viewer_phid.')',
|
|
|
|
|
'packages('.$viewer_phid.')',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$query->setParameter('needsAuditByPHIDs', $needs_tokens);
|
|
|
|
|
$query->setParameter('auditStatus', $status_open);
|
2014-04-27 09:43:05 -07:00
|
|
|
return $query;
|
2014-05-13 08:06:22 -07:00
|
|
|
case 'authored':
|
|
|
|
|
$query->setParameter('commitAuthorPHIDs', array($viewer->getPHID()));
|
|
|
|
|
return $query;
|
2014-04-28 08:26:08 -07:00
|
|
|
case 'problem':
|
|
|
|
|
$query->setParameter('commitAuthorPHIDs', array($viewer->getPHID()));
|
|
|
|
|
$query->setParameter(
|
|
|
|
|
'auditStatus',
|
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_CONCERN);
|
|
|
|
|
return $query;
|
2014-04-27 09:43:05 -07: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 10:43:52 -07:00
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_ACCEPTED => pht('Accepted'),
|
|
|
|
|
DiffusionCommitQuery::AUDIT_STATUS_PARTIAL => pht('Partially Audited'),
|
2014-04-27 09:43:05 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 08:49:32 -07: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);
|
2015-06-19 11:46:20 +01:00
|
|
|
$list = $view->buildList();
|
2014-05-08 08:49:32 -07:00
|
|
|
|
2015-06-19 11:46:20 +01:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
|
$result->setContent($list);
|
|
|
|
|
|
|
|
|
|
return $result;
|
2014-05-08 08:49:32 -07:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 13:13:32 -08:00
|
|
|
protected function getNewUserBody() {
|
|
|
|
|
|
|
|
|
|
$view = id(new PHUIBigInfoView())
|
|
|
|
|
->setIcon('fa-check-circle-o')
|
|
|
|
|
->setTitle(pht('Welcome to Audit'))
|
|
|
|
|
->setDescription(
|
|
|
|
|
pht('Post-commit code review and auditing. Audits you are assigned '.
|
|
|
|
|
'to will appear here.'));
|
|
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 09:43:05 -07:00
|
|
|
}
|