2011-03-31 08:27:06 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionLastModifiedController extends DiffusionController {
|
2011-03-31 08:27:06 +02:00
|
|
|
|
2013-09-27 19:49:45 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-05 19:34:04 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$response = $this->loadDiffusionContext();
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
2011-03-31 08:27:06 +02:00
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
2014-05-11 00:32:53 +02:00
|
|
|
$paths = $request->getStr('paths');
|
2015-05-05 12:20:11 +02:00
|
|
|
try {
|
|
|
|
$paths = phutil_json_decode($paths);
|
|
|
|
} catch (PhutilJSONParserException $ex) {
|
2014-05-11 00:57:16 +02:00
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
2014-05-11 00:32:53 +02:00
|
|
|
|
2014-05-11 01:46:32 +02:00
|
|
|
$modified_map = $this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.lastmodifiedquery',
|
|
|
|
array(
|
|
|
|
'paths' => array_fill_keys($paths, $drequest->getCommit()),
|
|
|
|
));
|
|
|
|
|
|
|
|
if ($modified_map) {
|
|
|
|
$commit_map = id(new DiffusionCommitQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withRepository($drequest->getRepository())
|
|
|
|
->withIdentifiers(array_values($modified_map))
|
|
|
|
->needCommitData(true)
|
|
|
|
->execute();
|
|
|
|
$commit_map = mpull($commit_map, null, 'getCommitIdentifier');
|
|
|
|
} else {
|
|
|
|
$commit_map = array();
|
|
|
|
}
|
|
|
|
|
2014-05-11 00:57:16 +02:00
|
|
|
$commits = array();
|
2014-05-11 00:32:53 +02:00
|
|
|
foreach ($paths as $path) {
|
2014-05-11 01:46:32 +02:00
|
|
|
$modified_at = idx($modified_map, $path);
|
|
|
|
if ($modified_at) {
|
|
|
|
$commit = idx($commit_map, $modified_at);
|
|
|
|
if ($commit) {
|
|
|
|
$commits[$path] = $commit;
|
2014-05-11 00:32:53 +02:00
|
|
|
}
|
2012-05-23 17:34:36 +02:00
|
|
|
}
|
2014-05-11 00:57:16 +02:00
|
|
|
}
|
|
|
|
|
2014-05-11 01:46:32 +02:00
|
|
|
$phids = array();
|
|
|
|
foreach ($commits as $commit) {
|
|
|
|
$data = $commit->getCommitData();
|
|
|
|
$phids[] = $data->getCommitDetail('authorPHID');
|
|
|
|
$phids[] = $data->getCommitDetail('committerPHID');
|
|
|
|
}
|
|
|
|
$phids = array_filter($phids);
|
2014-05-11 00:57:16 +02:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
|
|
|
|
|
|
|
$branch = $drequest->loadBranch();
|
2014-05-11 01:46:32 +02:00
|
|
|
if ($branch && $commits) {
|
2014-05-11 00:57:16 +02:00
|
|
|
$lint_query = id(new DiffusionLintCountQuery())
|
|
|
|
->withBranchIDs(array($branch->getID()))
|
|
|
|
->withPaths(array_keys($commits));
|
|
|
|
|
|
|
|
if ($drequest->getLint()) {
|
|
|
|
$lint_query->withCodes(array($drequest->getLint()));
|
|
|
|
}
|
|
|
|
|
|
|
|
$lint = $lint_query->execute();
|
|
|
|
} else {
|
|
|
|
$lint = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = array();
|
|
|
|
foreach ($commits as $path => $commit) {
|
|
|
|
$prequest = clone $drequest;
|
|
|
|
$prequest->setPath($path);
|
2011-04-03 01:39:23 +02:00
|
|
|
|
2014-05-11 00:57:16 +02:00
|
|
|
$output[$path] = $this->renderColumns(
|
2014-05-11 00:32:53 +02:00
|
|
|
$prequest,
|
|
|
|
$handles,
|
|
|
|
$commit,
|
2014-05-11 00:57:16 +02:00
|
|
|
idx($lint, $path));
|
2014-05-11 00:32:53 +02:00
|
|
|
}
|
2011-03-31 08:27:06 +02:00
|
|
|
|
2014-05-11 00:32:53 +02:00
|
|
|
return id(new AphrontAjaxResponse())->setContent($output);
|
2011-03-31 08:27:06 +02:00
|
|
|
}
|
2014-05-11 00:57:16 +02:00
|
|
|
|
|
|
|
private function renderColumns(
|
|
|
|
DiffusionRequest $drequest,
|
|
|
|
array $handles,
|
|
|
|
PhabricatorRepositoryCommit $commit = null,
|
|
|
|
$lint = null) {
|
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
if ($commit) {
|
|
|
|
$epoch = $commit->getEpoch();
|
|
|
|
$modified = DiffusionView::linkCommit(
|
|
|
|
$drequest->getRepository(),
|
|
|
|
$commit->getCommitIdentifier());
|
2016-03-18 16:59:21 +01:00
|
|
|
$date = $viewer->formatShortDateTime($epoch);
|
2014-05-11 00:57:16 +02:00
|
|
|
} else {
|
|
|
|
$modified = '';
|
|
|
|
$date = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = $commit->getCommitData();
|
|
|
|
if ($data) {
|
|
|
|
$author_phid = $data->getCommitDetail('authorPHID');
|
|
|
|
if ($author_phid && isset($handles[$author_phid])) {
|
|
|
|
$author = $handles[$author_phid]->renderLink();
|
|
|
|
} else {
|
|
|
|
$author = DiffusionView::renderName($data->getAuthorName());
|
|
|
|
}
|
|
|
|
|
|
|
|
$committer = $data->getCommitDetail('committer');
|
|
|
|
if ($committer) {
|
|
|
|
$committer_phid = $data->getCommitDetail('committerPHID');
|
|
|
|
if ($committer_phid && isset($handles[$committer_phid])) {
|
|
|
|
$committer = $handles[$committer_phid]->renderLink();
|
|
|
|
} else {
|
|
|
|
$committer = DiffusionView::renderName($committer);
|
|
|
|
}
|
|
|
|
if ($author != $committer) {
|
|
|
|
$author = hsprintf('%s/%s', $author, $committer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$details = AphrontTableView::renderSingleDisplayLine($data->getSummary());
|
|
|
|
} else {
|
|
|
|
$author = '';
|
|
|
|
$details = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$return = array(
|
|
|
|
'commit' => $modified,
|
|
|
|
'date' => $date,
|
|
|
|
'author' => $author,
|
|
|
|
'details' => $details,
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($lint !== null) {
|
|
|
|
$return['lint'] = phutil_tag(
|
|
|
|
'a',
|
2014-10-07 15:01:04 +02:00
|
|
|
array(
|
|
|
|
'href' => $drequest->generateURI(array(
|
|
|
|
'action' => 'lint',
|
|
|
|
'lint' => null,
|
|
|
|
)),
|
|
|
|
),
|
2014-05-11 00:57:16 +02:00
|
|
|
number_format($lint));
|
|
|
|
}
|
|
|
|
|
2015-03-20 22:54:35 +01:00
|
|
|
// The client treats these results as markup, so make sure they have been
|
|
|
|
// escaped correctly.
|
|
|
|
foreach ($return as $key => $value) {
|
|
|
|
$return[$key] = hsprintf('%s', $value);
|
|
|
|
}
|
|
|
|
|
2014-05-11 00:57:16 +02:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 08:27:06 +02:00
|
|
|
}
|