3 final class ReleephBranchSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
8 public function getResultTypeDescription() {
9 return pht('Releeph Branches');
12 public function canUseInPanelContext() {
16 public function getApplicationClassName() {
17 return 'PhabricatorReleephApplication';
20 public function setProduct(ReleephProject
$product) {
21 $this->product
= $product;
25 public function getProduct() {
26 return $this->product
;
29 public function buildSavedQueryFromRequest(AphrontRequest
$request) {
30 $saved = new PhabricatorSavedQuery();
32 $saved->setParameter('active', $request->getStr('active'));
37 public function buildQueryFromSavedQuery(PhabricatorSavedQuery
$saved) {
38 $query = id(new ReleephBranchQuery())
39 ->needCutPointCommits(true)
40 ->withProductPHIDs(array($this->getProduct()->getPHID()));
42 $active = $saved->getParameter('active');
43 $value = idx($this->getActiveValues(), $active);
44 if ($value !== null) {
45 $query->withStatus($value);
51 public function buildSearchForm(
52 AphrontFormView
$form,
53 PhabricatorSavedQuery
$saved_query) {
56 id(new AphrontFormSelectControl())
58 ->setLabel(pht('Show Branches'))
59 ->setValue($saved_query->getParameter('active'))
60 ->setOptions($this->getActiveOptions()));
63 protected function getURI($path) {
64 return '/releeph/product/'.$this->getProduct()->getID().'/'.$path;
67 protected function getBuiltinQueryNames() {
69 'open' => pht('Open'),
76 public function buildSavedQueryFromBuiltin($query_key) {
78 $query = $this->newSavedQuery();
79 $query->setQueryKey($query_key);
84 ->setParameter('active', 'open');
89 return parent
::buildSavedQueryFromBuiltin($query_key);
92 private function getActiveOptions() {
94 'open' => pht('Open Branches'),
95 'all' => pht('Open and Closed Branches'),
99 private function getActiveValues() {
101 'open' => ReleephBranchQuery
::STATUS_OPEN
,
102 'all' => ReleephBranchQuery
::STATUS_ALL
,
106 protected function renderResultList(
108 PhabricatorSavedQuery
$query,
112 assert_instances_of($branches, 'ReleephBranch');
114 $viewer = $this->getRequest()->getUser();
116 $products = mpull($branches, 'getProduct');
117 $repo_phids = mpull($products, 'getRepositoryPHID');
120 $repos = id(new PhabricatorRepositoryQuery())
122 ->withPHIDs($repo_phids)
124 $repos = mpull($repos, null, 'getPHID');
131 $requests = id(new ReleephRequestQuery())
133 ->withBranchIDs(mpull($branches, 'getID'))
134 ->withStatus(ReleephRequestQuery
::STATUS_OPEN
)
136 $requests = mgroup($requests, 'getBranchID');
139 $list = id(new PHUIObjectItemListView())
141 foreach ($branches as $branch) {
142 $diffusion_href = null;
143 $repo = idx($repos, $branch->getProduct()->getRepositoryPHID());
145 $drequest = DiffusionRequest
::newFromDictionary(
148 'repository' => $repo,
151 $diffusion_href = $drequest->generateURI(
153 'action' => 'branch',
154 'branch' => $branch->getName(),
158 $branch_link = $branch->getName();
159 if ($diffusion_href) {
160 $branch_link = phutil_tag(
163 'href' => $diffusion_href,
168 $item = id(new PHUIObjectItemView())
169 ->setHeader($branch->getDisplayName())
170 ->setHref($this->getApplicationURI('branch/'.$branch->getID().'/'))
171 ->addAttribute($branch_link);
173 if (!$branch->getIsActive()) {
174 $item->setDisabled(true);
177 $commit = $branch->getCutPointCommit();
181 phabricator_datetime($commit->getEpoch(), $viewer));
184 $open_count = count(idx($requests, $branch->getID(), array()));
186 $item->setStatusIcon('fa-code-fork orange');
190 '%s Open Pull Request(s)',
191 new PhutilNumber($open_count)));
194 $list->addItem($item);
197 return id(new PhabricatorApplicationSearchResultView())
198 ->setObjectList($list);