3 final class ReleephRequestSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
9 public function getResultTypeDescription() {
10 return pht('Releeph Pull Requests');
13 public function getApplicationClassName() {
14 return 'PhabricatorReleephApplication';
17 public function canUseInPanelContext() {
21 public function setBranch(ReleephBranch
$branch) {
22 $this->branch
= $branch;
26 public function getBranch() {
30 public function setBaseURI($base_uri) {
31 $this->baseURI
= $base_uri;
35 public function buildSavedQueryFromRequest(AphrontRequest
$request) {
36 $saved = new PhabricatorSavedQuery();
38 $saved->setParameter('status', $request->getStr('status'));
39 $saved->setParameter('severity', $request->getStr('severity'));
42 $this->readUsersFromRequest($request, 'requestors'));
47 public function buildQueryFromSavedQuery(PhabricatorSavedQuery
$saved) {
48 $query = id(new ReleephRequestQuery())
49 ->withBranchIDs(array($this->getBranch()->getID()));
51 $status = $saved->getParameter('status');
52 $status = idx($this->getStatusValues(), $status);
54 $query->withStatus($status);
57 $severity = $saved->getParameter('severity');
59 $query->withSeverities(array($severity));
62 $requestor_phids = $saved->getParameter('requestorPHIDs');
63 if ($requestor_phids) {
64 $query->withRequestorPHIDs($requestor_phids);
70 public function buildSearchForm(
71 AphrontFormView
$form,
72 PhabricatorSavedQuery
$saved_query) {
74 $requestor_phids = $saved_query->getParameter('requestorPHIDs', array());
78 id(new AphrontFormSelectControl())
80 ->setLabel(pht('Status'))
81 ->setValue($saved_query->getParameter('status'))
82 ->setOptions($this->getStatusOptions()))
84 id(new AphrontFormSelectControl())
86 ->setLabel(pht('Severity'))
87 ->setValue($saved_query->getParameter('severity'))
88 ->setOptions($this->getSeverityOptions()))
90 id(new AphrontFormTokenizerControl())
91 ->setDatasource(new PhabricatorPeopleDatasource())
92 ->setName('requestors')
93 ->setLabel(pht('Requestors'))
94 ->setValue($requestor_phids));
97 protected function getURI($path) {
98 return $this->baseURI
.$path;
101 protected function getBuiltinQueryNames() {
103 'open' => pht('Open Requests'),
104 'all' => pht('All Requests'),
107 if ($this->requireViewer()->isLoggedIn()) {
108 $names['requested'] = pht('Requested');
114 public function buildSavedQueryFromBuiltin($query_key) {
116 $query = $this->newSavedQuery();
117 $query->setQueryKey($query_key);
119 switch ($query_key) {
121 return $query->setParameter('status', 'open');
125 return $query->setParameter(
127 array($this->requireViewer()->getPHID()));
130 return parent
::buildSavedQueryFromBuiltin($query_key);
133 private function getStatusOptions() {
135 '' => pht('(All Requests)'),
136 'open' => pht('Open Requests'),
137 'requested' => pht('Pull Requested'),
138 'needs-pull' => pht('Needs Pull'),
139 'rejected' => pht('Rejected'),
140 'abandoned' => pht('Abandoned'),
141 'pulled' => pht('Pulled'),
142 'needs-revert' => pht('Needs Revert'),
143 'reverted' => pht('Reverted'),
147 private function getStatusValues() {
149 'open' => ReleephRequestQuery
::STATUS_OPEN
,
150 'requested' => ReleephRequestQuery
::STATUS_REQUESTED
,
151 'needs-pull' => ReleephRequestQuery
::STATUS_NEEDS_PULL
,
152 'rejected' => ReleephRequestQuery
::STATUS_REJECTED
,
153 'abandoned' => ReleephRequestQuery
::STATUS_ABANDONED
,
154 'pulled' => ReleephRequestQuery
::STATUS_PULLED
,
155 'needs-revert' => ReleephRequestQuery
::STATUS_NEEDS_REVERT
,
156 'reverted' => ReleephRequestQuery
::STATUS_REVERTED
,
160 private function getSeverityOptions() {
161 if (ReleephDefaultFieldSelector
::isFacebook()) {
163 '' => pht('(All Severities)'),
165 12 => pht('PIGGYBACK'),
166 13 => pht('RELEASE'),
168 15 => pht('PARKING'),
172 '' => pht('(All Severities)'),
173 ReleephSeverityFieldSpecification
::HOTFIX
=> pht('Hotfix'),
174 ReleephSeverityFieldSpecification
::RELEASE
=> pht('Release'),
179 protected function renderResultList(
181 PhabricatorSavedQuery
$query,
184 assert_instances_of($requests, 'ReleephRequest');
185 $viewer = $this->requireViewer();
187 // TODO: This is generally a bit sketchy, but we don't do this kind of
188 // thing elsewhere at the moment. For the moment it shouldn't be hugely
189 // costly, and we can batch things later. Generally, this commits fewer
190 // sins than the old code did.
192 $engine = id(new PhabricatorMarkupEngine())
193 ->setViewer($viewer);
196 foreach ($requests as $pull) {
197 $field_list = PhabricatorCustomField
::getObjectFields(
199 PhabricatorCustomField
::ROLE_VIEW
);
203 ->readFieldsFromStorage($pull);
205 foreach ($field_list->getFields() as $field) {
206 if ($field->shouldMarkup()) {
207 $field->setMarkupEngine($engine);
211 $list[] = id(new ReleephRequestView())
213 ->setCustomFields($field_list)
214 ->setPullRequest($pull)
215 ->setIsListView(true);
218 // This is quite sketchy, but the list has not actually rendered yet, so
219 // this still allows us to batch the markup rendering.
222 return id(new PhabricatorApplicationSearchResultView())