public function processRequest()
 {
     $drequest = $this->getDiffusionRequest();
     $request = $this->getRequest();
     $user = $request->getUser();
     $repository = $drequest->getRepository();
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setOffset($request->getInt('offset'));
     // TODO: Add support for branches that contain commit
     $query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
     $query->setOffset($pager->getOffset());
     $query->setLimit($pager->getPageSize() + 1);
     $branches = $query->loadBranches();
     $branches = $pager->sliceResults($branches);
     $content = null;
     if (!$branches) {
         $content = new AphrontErrorView();
         $content->setTitle('No Branches');
         $content->appendChild('This repository has no branches.');
         $content->setSeverity(AphrontErrorView::SEVERITY_NODATA);
     } else {
         $commits = id(new PhabricatorAuditCommitQuery())->withIdentifiers($drequest->getRepository()->getID(), mpull($branches, 'getHeadCommitIdentifier'))->needCommitData(true)->execute();
         $view = id(new DiffusionBranchTableView())->setBranches($branches)->setUser($user)->setCommits($commits)->setDiffusionRequest($drequest);
         $panel = id(new AphrontPanelView())->setHeader('Branches')->appendChild($view)->appendChild($pager);
         $content = $panel;
     }
     return $this->buildStandardPageResponse(array($this->buildCrumbs(array('branches' => true)), $content), array('title' => array('Branches', $repository->getCallsign() . ' Repository')));
 }
 private function buildBranchListTable(DiffusionRequest $drequest)
 {
     if ($drequest->getBranch() !== null) {
         $limit = 15;
         $branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
         $branch_query->setLimit($limit + 1);
         $branches = $branch_query->loadBranches();
         if (!$branches) {
             return null;
         }
         $more_branches = count($branches) > $limit;
         $branches = array_slice($branches, 0, $limit);
         $commits = id(new PhabricatorAuditCommitQuery())->withIdentifiers($drequest->getRepository()->getID(), mpull($branches, 'getHeadCommitIdentifier'))->needCommitData(true)->execute();
         $table = new DiffusionBranchTableView();
         $table->setDiffusionRequest($drequest);
         $table->setBranches($branches);
         $table->setCommits($commits);
         $table->setUser($this->getRequest()->getUser());
         $panel = new AphrontPanelView();
         $panel->setHeader('Branches');
         if ($more_branches) {
             $panel->setCaption('Showing ' . $limit . ' branches.');
         }
         $panel->addButton(phutil_render_tag('a', array('href' => $drequest->generateURI(array('action' => 'branches')), 'class' => 'grey button'), "Show All Branches »"));
         $panel->appendChild($table);
         return $panel;
     }
     return null;
 }
 public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $content = array();
     $crumbs = $this->buildCrumbs();
     $content[] = $crumbs;
     $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest);
     $history_query->setLimit(15);
     $history = $history_query->loadHistory();
     $browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
     $browse_results = $browse_query->loadPaths();
     $phids = array();
     foreach ($history as $item) {
         $data = $item->getCommitData();
         if ($data) {
             if ($data->getCommitDetail('authorPHID')) {
                 $phids[$data->getCommitDetail('authorPHID')] = true;
             }
         }
     }
     foreach ($browse_results as $item) {
         $data = $item->getLastCommitData();
         if ($data) {
             if ($data->getCommitDetail('authorPHID')) {
                 $phids[$data->getCommitDetail('authorPHID')] = true;
             }
         }
     }
     $phids = array_keys($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $history_table = new DiffusionHistoryTableView();
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHandles($handles);
     $history_table->setHistory($history);
     $callsign = $drequest->getRepository()->getCallsign();
     $all = phutil_render_tag('a', array('href' => "/diffusion/{$callsign}/history/"), 'View Full Commit History');
     $panel = new AphrontPanelView();
     $panel->setHeader("Recent Commits · {$all}");
     $panel->appendChild($history_table);
     $content[] = $panel;
     $browse_table = new DiffusionBrowseTableView();
     $browse_table->setDiffusionRequest($drequest);
     $browse_table->setHandles($handles);
     $browse_table->setPaths($browse_results);
     $browse_panel = new AphrontPanelView();
     $browse_panel->setHeader('Browse Repository');
     $browse_panel->appendChild($browse_table);
     $content[] = $browse_panel;
     if ($drequest->getBranch() !== null) {
         $branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
         $branches = $branch_query->loadBranches();
         $branch_table = new DiffusionBranchTableView();
         $branch_table->setDiffusionRequest($drequest);
         $branch_table->setBranches($branches);
         $branch_panel = new AphrontPanelView();
         $branch_panel->setHeader('Branches');
         $branch_panel->appendChild($branch_table);
         $content[] = $branch_panel;
     }
     return $this->buildStandardPageResponse($content, array('title' => 'Diffusion'));
 }