2011-03-12 16:17:34 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionBranchTableView extends DiffusionView {
|
|
|
|
|
|
|
|
private $branches;
|
2012-05-10 09:28:19 +02:00
|
|
|
private $commits = array();
|
2011-03-12 16:17:34 -08:00
|
|
|
|
|
|
|
public function setBranches(array $branches) {
|
2014-01-17 16:10:56 -08:00
|
|
|
assert_instances_of($branches, 'DiffusionRepositoryRef');
|
2011-03-12 16:17:34 -08:00
|
|
|
$this->branches = $branches;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-05-08 22:28:27 +02:00
|
|
|
public function setCommits(array $commits) {
|
2014-01-17 16:10:56 -08:00
|
|
|
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
|
2012-05-08 22:28:27 +02:00
|
|
|
$this->commits = mpull($commits, null, 'getCommitIdentifier');
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-03-12 16:17:34 -08:00
|
|
|
public function render() {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$current_branch = $drequest->getBranch();
|
2014-08-25 16:14:19 -07:00
|
|
|
$repository = $drequest->getRepository();
|
2015-10-06 07:38:15 -07:00
|
|
|
$commits = $this->commits;
|
|
|
|
$viewer = $this->getUser();
|
|
|
|
|
|
|
|
$buildables = $this->loadBuildables($commits);
|
|
|
|
$have_builds = false;
|
2014-08-25 16:14:19 -07:00
|
|
|
|
2015-04-27 03:51:21 -07:00
|
|
|
$can_close_branches = ($repository->isHg());
|
|
|
|
|
2014-08-25 16:14:19 -07:00
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
|
|
|
|
|
|
|
$doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: Autoclose');
|
2011-03-12 16:17:34 -08:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
$rowc = array();
|
|
|
|
foreach ($this->branches as $branch) {
|
2015-10-06 07:38:15 -07:00
|
|
|
$commit = idx($commits, $branch->getCommitIdentifier());
|
2012-05-08 22:28:27 +02:00
|
|
|
if ($commit) {
|
2013-10-30 13:06:28 -07:00
|
|
|
$details = $commit->getSummary();
|
2016-03-18 08:59:21 -07:00
|
|
|
$datetime = $viewer->formatShortDateTime($commit->getEpoch());
|
2015-10-06 07:38:15 -07:00
|
|
|
$buildable = idx($buildables, $commit->getPHID());
|
|
|
|
if ($buildable) {
|
|
|
|
$build_status = $this->renderBuildable($buildable);
|
|
|
|
$have_builds = true;
|
|
|
|
} else {
|
|
|
|
$build_status = null;
|
|
|
|
}
|
2012-05-08 22:28:27 +02:00
|
|
|
} else {
|
|
|
|
$datetime = null;
|
|
|
|
$details = null;
|
2015-10-06 07:38:15 -07:00
|
|
|
$build_status = null;
|
2012-05-08 22:28:27 +02:00
|
|
|
}
|
|
|
|
|
2014-08-25 16:14:19 -07:00
|
|
|
switch ($repository->shouldSkipAutocloseBranch($branch->getShortName())) {
|
|
|
|
case PhabricatorRepository::BECAUSE_REPOSITORY_IMPORTING:
|
|
|
|
$icon = 'fa-times bluegrey';
|
|
|
|
$tip = pht('Repository Importing');
|
|
|
|
break;
|
|
|
|
case PhabricatorRepository::BECAUSE_AUTOCLOSE_DISABLED:
|
|
|
|
$icon = 'fa-times bluegrey';
|
|
|
|
$tip = pht('Repository Autoclose Disabled');
|
|
|
|
break;
|
|
|
|
case PhabricatorRepository::BECAUSE_BRANCH_UNTRACKED:
|
|
|
|
$icon = 'fa-times bluegrey';
|
|
|
|
$tip = pht('Branch Untracked');
|
|
|
|
break;
|
|
|
|
case PhabricatorRepository::BECAUSE_BRANCH_NOT_AUTOCLOSE:
|
|
|
|
$icon = 'fa-times bluegrey';
|
|
|
|
$tip = pht('Branch Autoclose Disabled');
|
|
|
|
break;
|
|
|
|
case null:
|
|
|
|
$icon = 'fa-check bluegrey';
|
|
|
|
$tip = pht('Autoclose Enabled');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$icon = 'fa-question';
|
|
|
|
$tip = pht('Status Unknown');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$status_icon = id(new PHUIIconView())
|
2016-01-27 20:38:01 -08:00
|
|
|
->setIcon($icon)
|
2014-08-25 16:14:19 -07:00
|
|
|
->addSigil('has-tooltip')
|
|
|
|
->setHref($doc_href)
|
|
|
|
->setMetadata(
|
|
|
|
array(
|
|
|
|
'tip' => $tip,
|
|
|
|
'size' => 200,
|
|
|
|
));
|
|
|
|
|
2015-04-27 03:51:21 -07:00
|
|
|
$fields = $branch->getRawFields();
|
|
|
|
$closed = idx($fields, 'closed');
|
|
|
|
if ($closed) {
|
|
|
|
$status = pht('Closed');
|
|
|
|
} else {
|
|
|
|
$status = pht('Open');
|
|
|
|
}
|
|
|
|
|
2011-03-12 16:17:34 -08:00
|
|
|
$rows[] = array(
|
2015-10-06 07:38:15 -07:00
|
|
|
$this->linkBranchHistory($branch->getShortName()),
|
2013-01-17 18:43:35 -08:00
|
|
|
phutil_tag(
|
2011-03-31 01:07:51 -07:00
|
|
|
'a',
|
|
|
|
array(
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-19 19:52:14 -07:00
|
|
|
'href' => $drequest->generateURI(
|
|
|
|
array(
|
2012-04-18 08:02:08 -07:00
|
|
|
'action' => 'browse',
|
2014-01-17 16:10:56 -08:00
|
|
|
'branch' => $branch->getShortName(),
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-19 19:52:14 -07:00
|
|
|
)),
|
2011-03-31 01:07:51 -07:00
|
|
|
),
|
2014-01-17 16:10:56 -08:00
|
|
|
$branch->getShortName()),
|
2011-03-12 16:17:34 -08:00
|
|
|
self::linkCommit(
|
|
|
|
$drequest->getRepository(),
|
2014-01-17 16:10:56 -08:00
|
|
|
$branch->getCommitIdentifier()),
|
2015-10-06 07:38:15 -07:00
|
|
|
$build_status,
|
2015-04-27 03:51:21 -07:00
|
|
|
$status,
|
2015-10-06 07:38:15 -07:00
|
|
|
AphrontTableView::renderSingleDisplayLine($details),
|
2014-08-25 16:14:19 -07:00
|
|
|
$status_icon,
|
2012-05-08 22:28:27 +02:00
|
|
|
$datetime,
|
2011-03-12 16:17:34 -08:00
|
|
|
);
|
2014-01-17 16:10:56 -08:00
|
|
|
if ($branch->getShortName() == $current_branch) {
|
2011-03-12 16:17:34 -08:00
|
|
|
$rowc[] = 'highlighted';
|
|
|
|
} else {
|
|
|
|
$rowc[] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = new AphrontTableView($rows);
|
|
|
|
$view->setHeaders(
|
|
|
|
array(
|
2015-10-06 07:38:15 -07:00
|
|
|
null,
|
2013-05-11 08:23:19 -07:00
|
|
|
pht('Branch'),
|
|
|
|
pht('Head'),
|
2015-10-06 07:38:15 -07:00
|
|
|
null,
|
2015-04-27 03:51:21 -07:00
|
|
|
pht('State'),
|
2013-05-11 08:23:19 -07:00
|
|
|
pht('Details'),
|
2015-10-06 07:38:15 -07:00
|
|
|
null,
|
|
|
|
pht('Committed'),
|
2011-03-12 16:17:34 -08:00
|
|
|
));
|
|
|
|
$view->setColumnClasses(
|
|
|
|
array(
|
2012-05-08 22:28:27 +02:00
|
|
|
'',
|
2012-04-18 08:02:08 -07:00
|
|
|
'pri',
|
2012-05-08 22:28:27 +02:00
|
|
|
'',
|
2015-10-06 07:38:15 -07:00
|
|
|
'icon',
|
2012-05-08 22:28:27 +02:00
|
|
|
'',
|
2015-10-06 07:38:15 -07:00
|
|
|
'wide',
|
2014-08-25 16:14:19 -07:00
|
|
|
'',
|
2016-03-18 08:59:21 -07:00
|
|
|
'right',
|
2011-03-12 16:17:34 -08:00
|
|
|
));
|
2015-04-27 03:51:21 -07:00
|
|
|
$view->setColumnVisibility(
|
|
|
|
array(
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
2015-10-06 07:38:15 -07:00
|
|
|
$have_builds,
|
2015-04-27 03:51:21 -07:00
|
|
|
$can_close_branches,
|
|
|
|
));
|
2011-03-12 16:17:34 -08:00
|
|
|
$view->setRowClasses($rowc);
|
|
|
|
return $view->render();
|
|
|
|
}
|
|
|
|
|
2015-10-06 07:38:15 -07:00
|
|
|
|
2011-03-12 16:17:34 -08:00
|
|
|
}
|