1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 03:12:41 +01:00
phorge-phorge/src/applications/diffusion/controller/DiffusionCommitBranchesController.php
epriestley c6d91938e8 Show first 10 branches, then "More Branches" for commits on huge numbers of branches
Summary: Fixes T9562. We already do this for tags, but didn't have similar logic for branches. Implement that logic.

Test Plan:
  - Set limit to 1, saw "More branches", clicked it, got the correct results.
  - Verified that branch table with no specified commit still works properly.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9562

Differential Revision: https://secure.phabricator.com/D15284
2016-02-16 15:10:01 -08:00

59 lines
1.5 KiB
PHP

<?php
final class DiffusionCommitBranchesController extends DiffusionController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$branch_limit = 10;
$branches = DiffusionRepositoryRef::loadAllFromDictionaries(
$this->callConduitWithDiffusionRequest(
'diffusion.branchquery',
array(
'contains' => $drequest->getCommit(),
'limit' => $branch_limit + 1,
)));
$has_more_branches = (count($branches) > $branch_limit);
$branches = array_slice($branches, 0, $branch_limit);
$branch_links = array();
foreach ($branches as $branch) {
$branch_links[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'branch' => $branch->getShortName(),
)),
),
$branch->getShortName());
}
if ($has_more_branches) {
$branch_links[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'branches',
)),
),
pht("More Branches\xE2\x80\xA6"));
}
return id(new AphrontAjaxResponse())
->setContent($branch_links ? implode(', ', $branch_links) : pht('None'));
}
}