3 final class PhabricatorCommitSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Diffusion Commits');
10 public function getApplicationClassName() {
11 return 'PhabricatorDiffusionApplication';
14 public function newQuery() {
15 return id(new DiffusionCommitQuery())
16 ->needAuditRequests(true)
17 ->needCommitData(true)
18 ->needIdentities(true)
22 protected function newResultBuckets() {
23 return DiffusionCommitResultBucket
::getAllResultBuckets();
26 protected function buildQueryFromParameters(array $map) {
27 $query = $this->newQuery();
29 if ($map['responsiblePHIDs']) {
30 $query->withResponsiblePHIDs($map['responsiblePHIDs']);
33 if ($map['auditorPHIDs']) {
34 $query->withAuditorPHIDs($map['auditorPHIDs']);
37 if ($map['authorPHIDs']) {
38 $query->withAuthorPHIDs($map['authorPHIDs']);
41 if ($map['statuses']) {
42 $query->withStatuses($map['statuses']);
45 if ($map['repositoryPHIDs']) {
46 $query->withRepositoryPHIDs($map['repositoryPHIDs']);
49 if ($map['packagePHIDs']) {
50 $query->withPackagePHIDs($map['packagePHIDs']);
53 if ($map['unreachable'] !== null) {
54 $query->withUnreachable($map['unreachable']);
57 if ($map['permanent'] !== null) {
58 $query->withPermanent($map['permanent']);
61 if ($map['ancestorsOf']) {
62 $query->withAncestorsOf($map['ancestorsOf']);
65 if ($map['identifiers']) {
66 $query->withIdentifiers($map['identifiers']);
72 protected function buildCustomSearchFields() {
74 id(new PhabricatorSearchDatasourceField())
75 ->setLabel(pht('Responsible Users'))
76 ->setKey('responsiblePHIDs')
77 ->setConduitKey('responsible')
78 ->setAliases(array('responsible', 'responsibles', 'responsiblePHID'))
79 ->setDatasource(new DifferentialResponsibleDatasource())
82 'Find commits where given users, projects, or packages are '.
83 'responsible for the next steps in the audit workflow.')),
84 id(new PhabricatorUsersSearchField())
85 ->setLabel(pht('Authors'))
86 ->setKey('authorPHIDs')
87 ->setConduitKey('authors')
88 ->setAliases(array('author', 'authors', 'authorPHID'))
89 ->setDescription(pht('Find commits authored by particular users.')),
90 id(new PhabricatorSearchDatasourceField())
91 ->setLabel(pht('Auditors'))
92 ->setKey('auditorPHIDs')
93 ->setConduitKey('auditors')
94 ->setAliases(array('auditor', 'auditors', 'auditorPHID'))
95 ->setDatasource(new DiffusionAuditorFunctionDatasource())
98 'Find commits where given users, projects, or packages are '.
100 id(new PhabricatorSearchCheckboxesField())
101 ->setLabel(pht('Audit Status'))
103 ->setAliases(array('status'))
104 ->setOptions(DiffusionCommitAuditStatus
::newOptions())
105 ->setDeprecatedOptions(
106 DiffusionCommitAuditStatus
::newDeprecatedOptions())
107 ->setDescription(pht('Find commits with given audit statuses.')),
108 id(new PhabricatorSearchDatasourceField())
109 ->setLabel(pht('Repositories'))
110 ->setKey('repositoryPHIDs')
111 ->setConduitKey('repositories')
112 ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
113 ->setDatasource(new DiffusionRepositoryFunctionDatasource())
114 ->setDescription(pht('Find commits in particular repositories.')),
115 id(new PhabricatorSearchDatasourceField())
116 ->setLabel(pht('Packages'))
117 ->setKey('packagePHIDs')
118 ->setConduitKey('packages')
119 ->setAliases(array('package', 'packages', 'packagePHID'))
120 ->setDatasource(new PhabricatorOwnersPackageDatasource())
122 pht('Find commits which affect given packages.')),
123 id(new PhabricatorSearchThreeStateField())
124 ->setLabel(pht('Unreachable'))
125 ->setKey('unreachable')
128 pht('Show Only Unreachable Commits'),
129 pht('Hide Unreachable Commits'))
132 'Find or exclude unreachable commits which are not ancestors of '.
133 'any branch, tag, or ref.')),
134 id(new PhabricatorSearchThreeStateField())
135 ->setLabel(pht('Permanent'))
136 ->setKey('permanent')
139 pht('Show Only Permanent Commits'),
140 pht('Hide Permanent Commits'))
143 'Find or exclude permanent commits which are ancestors of '.
144 'any permanent branch, tag, or ref.')),
145 id(new PhabricatorSearchStringListField())
146 ->setLabel(pht('Ancestors Of'))
147 ->setKey('ancestorsOf')
150 'Find commits which are ancestors of a particular ref, '.
152 id(new PhabricatorSearchStringListField())
153 ->setLabel(pht('Identifiers'))
154 ->setKey('identifiers')
157 'Find commits with particular identifiers (usually, hashes). '.
158 'Supports full or partial identifiers (like "abcd12340987..." or '.
159 '"abcd1234") and qualified or unqualified identifiers (like '.
160 '"rXabcd1234" or "abcd1234").')),
164 protected function getURI($path) {
165 return '/diffusion/commit/'.$path;
168 protected function getBuiltinQueryNames() {
171 if ($this->requireViewer()->isLoggedIn()) {
172 $names['active'] = pht('Active Audits');
173 $names['authored'] = pht('Authored');
174 $names['audited'] = pht('Audited');
177 $names['all'] = pht('All Commits');
182 public function buildSavedQueryFromBuiltin($query_key) {
183 $query = $this->newSavedQuery();
184 $query->setQueryKey($query_key);
185 $viewer = $this->requireViewer();
187 $viewer_phid = $viewer->getPHID();
188 switch ($query_key) {
192 $bucket_key = DiffusionCommitRequiredActionResultBucket
::BUCKETKEY
;
194 $open = DiffusionCommitAuditStatus
::getOpenStatusConstants();
197 ->setParameter('responsiblePHIDs', array($viewer_phid))
198 ->setParameter('statuses', $open)
199 ->setParameter('bucket', $bucket_key)
200 ->setParameter('unreachable', false);
204 ->setParameter('authorPHIDs', array($viewer_phid));
208 ->setParameter('auditorPHIDs', array($viewer_phid));
212 return parent
::buildSavedQueryFromBuiltin($query_key);
215 protected function renderResultList(
217 PhabricatorSavedQuery
$query,
219 assert_instances_of($commits, 'PhabricatorRepositoryCommit');
220 $viewer = $this->requireViewer();
222 $bucket = $this->getResultBucket($query);
224 $template = id(new DiffusionCommitGraphView())
226 ->setShowAuditors(true);
230 $bucket->setViewer($viewer);
233 $groups = $bucket->newResultGroups($query, $commits);
235 foreach ($groups as $group) {
236 // Don't show groups in Dashboard Panels
237 if ($group->getObjects() ||
!$this->isPanelContext()) {
238 $item_list = id(clone $template)
239 ->setCommits($group->getObjects())
240 ->newObjectItemListView();
242 $views[] = $item_list
243 ->setHeader($group->getName())
244 ->setNoDataString($group->getNoDataString());
247 } catch (Exception
$ex) {
248 $this->addError($ex->getMessage());
253 $item_list = id(clone $template)
254 ->setCommits($commits)
255 ->newObjectItemListView();
257 $views[] = $item_list
258 ->setNoDataString(pht('No commits found.'));
261 return id(new PhabricatorApplicationSearchResultView())
262 ->setContent($views);
265 protected function getNewUserBody() {
267 $view = id(new PHUIBigInfoView())
268 ->setIcon('fa-check-circle-o')
269 ->setTitle(pht('Welcome to Audit'))
271 pht('Post-commit code review and auditing. Audits you are assigned '.
272 'to will appear here.'));