Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / audit / query / PhabricatorCommitSearchEngine.php
blob8b7751c79567725ca7abd7d9f6402f078624ef11
1 <?php
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)
19 ->needDrafts(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']);
69 return $query;
72 protected function buildCustomSearchFields() {
73 return array(
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())
80 ->setDescription(
81 pht(
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())
96 ->setDescription(
97 pht(
98 'Find commits where given users, projects, or packages are '.
99 'auditors.')),
100 id(new PhabricatorSearchCheckboxesField())
101 ->setLabel(pht('Audit Status'))
102 ->setKey('statuses')
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())
121 ->setDescription(
122 pht('Find commits which affect given packages.')),
123 id(new PhabricatorSearchThreeStateField())
124 ->setLabel(pht('Unreachable'))
125 ->setKey('unreachable')
126 ->setOptions(
127 pht('(Show All)'),
128 pht('Show Only Unreachable Commits'),
129 pht('Hide Unreachable Commits'))
130 ->setDescription(
131 pht(
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')
137 ->setOptions(
138 pht('(Show All)'),
139 pht('Show Only Permanent Commits'),
140 pht('Hide Permanent Commits'))
141 ->setDescription(
142 pht(
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')
148 ->setDescription(
149 pht(
150 'Find commits which are ancestors of a particular ref, '.
151 'like "master".')),
152 id(new PhabricatorSearchStringListField())
153 ->setLabel(pht('Identifiers'))
154 ->setKey('identifiers')
155 ->setDescription(
156 pht(
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() {
169 $names = array();
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');
179 return $names;
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) {
189 case 'all':
190 return $query;
191 case 'active':
192 $bucket_key = DiffusionCommitRequiredActionResultBucket::BUCKETKEY;
194 $open = DiffusionCommitAuditStatus::getOpenStatusConstants();
196 $query
197 ->setParameter('responsiblePHIDs', array($viewer_phid))
198 ->setParameter('statuses', $open)
199 ->setParameter('bucket', $bucket_key)
200 ->setParameter('unreachable', false);
201 return $query;
202 case 'authored':
203 $query
204 ->setParameter('authorPHIDs', array($viewer_phid));
205 return $query;
206 case 'audited':
207 $query
208 ->setParameter('auditorPHIDs', array($viewer_phid));
209 return $query;
212 return parent::buildSavedQueryFromBuiltin($query_key);
215 protected function renderResultList(
216 array $commits,
217 PhabricatorSavedQuery $query,
218 array $handles) {
219 assert_instances_of($commits, 'PhabricatorRepositoryCommit');
220 $viewer = $this->requireViewer();
222 $bucket = $this->getResultBucket($query);
224 $template = id(new DiffusionCommitGraphView())
225 ->setViewer($viewer)
226 ->setShowAuditors(true);
228 $views = array();
229 if ($bucket) {
230 $bucket->setViewer($viewer);
232 try {
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());
252 if (!$views) {
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'))
270 ->setDescription(
271 pht('Post-commit code review and auditing. Audits you are assigned '.
272 'to will appear here.'));
274 return $view;