Differential D14803 Diff 36600 src/applications/diffusion/controller/DiffusionLastModifiedController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionLastModifiedController.php
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if ($branch && $commits) { | ||||
->withBranchIDs(array($branch->getID())) | ->withBranchIDs(array($branch->getID())) | ||||
->withPaths(array_keys($commits)); | ->withPaths(array_keys($commits)); | ||||
if ($drequest->getLint()) { | if ($drequest->getLint()) { | ||||
$lint_query->withCodes(array($drequest->getLint())); | $lint_query->withCodes(array($drequest->getLint())); | ||||
} | } | ||||
$lint = $lint_query->execute(); | $lint = $lint_query->execute(); | ||||
$paths = array_keys($commits); | |||||
$path_map = id(new DiffusionPathIDQuery($paths))->loadPathIDs(); | |||||
$commit_id = $drequest->loadCommit()->getID(); | |||||
$coverage_rows = queryfx_all( | |||||
id(new PhabricatorRepository())->establishConnection('r'), | |||||
'SELECT * FROM %T | |||||
WHERE branchID = %d | |||||
AND pathID IN (%Ld) | |||||
AND commitID = %d', | |||||
PhabricatorRepository::TABLE_COVERAGE, | |||||
$branch->getID(), | |||||
$path_map, | |||||
$commit_id); | |||||
$coverage = array(); | |||||
$path_map = array_flip($path_map); | |||||
foreach ($coverage_rows as $coverage_row) { | |||||
$covered_path = $path_map[$coverage_row['pathID']]; | |||||
$report = $coverage_row['coverage']; | |||||
$cov = substr_count($report, 'C'); | |||||
$uncov = substr_count($report, 'U'); | |||||
$total = $cov + $uncov; | |||||
$is_dir = substr($covered_path, strlen($covered_path) - 1, 1) === '/'; | |||||
$coverage[$covered_path] = array( | |||||
'cov' => $cov, | |||||
'uncov' => $uncov, | |||||
'total' => $total, | |||||
'is_dir' => $is_dir, | |||||
); | |||||
} | |||||
$largest = max(ipull($coverage, 'total')); | |||||
foreach ($coverage as $covered_path => $coverage_info) { | |||||
$coverage[$covered_path]['largest'] = $largest; | |||||
} | |||||
} else { | } else { | ||||
$lint = array(); | $lint = array(); | ||||
$coverage = array(); | |||||
} | } | ||||
$output = array(); | $output = array(); | ||||
foreach ($commits as $path => $commit) { | foreach ($commits as $path => $commit) { | ||||
$prequest = clone $drequest; | $prequest = clone $drequest; | ||||
$prequest->setPath($path); | $prequest->setPath($path); | ||||
$output[$path] = $this->renderColumns( | $output[$path] = $this->renderColumns( | ||||
$prequest, | $prequest, | ||||
$handles, | $handles, | ||||
$commit, | $commit, | ||||
idx($lint, $path)); | idx($lint, $path), | ||||
idx($coverage, $path)); | |||||
} | } | ||||
return id(new AphrontAjaxResponse())->setContent($output); | return id(new AphrontAjaxResponse())->setContent($output); | ||||
} | } | ||||
private function renderColumns( | private function renderColumns( | ||||
DiffusionRequest $drequest, | DiffusionRequest $drequest, | ||||
array $handles, | array $handles, | ||||
PhabricatorRepositoryCommit $commit = null, | PhabricatorRepositoryCommit $commit = null, | ||||
$lint = null) { | $lint = null, | ||||
$coverage = null) { | |||||
assert_instances_of($handles, 'PhabricatorObjectHandle'); | assert_instances_of($handles, 'PhabricatorObjectHandle'); | ||||
$viewer = $this->getRequest()->getUser(); | $viewer = $this->getRequest()->getUser(); | ||||
if ($commit) { | if ($commit) { | ||||
$epoch = $commit->getEpoch(); | $epoch = $commit->getEpoch(); | ||||
$modified = DiffusionView::linkCommit( | $modified = DiffusionView::linkCommit( | ||||
$drequest->getRepository(), | $drequest->getRepository(), | ||||
$commit->getCommitIdentifier()); | $commit->getCommitIdentifier()); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if ($lint !== null) { | ||||
'href' => $drequest->generateURI(array( | 'href' => $drequest->generateURI(array( | ||||
'action' => 'lint', | 'action' => 'lint', | ||||
'lint' => null, | 'lint' => null, | ||||
)), | )), | ||||
), | ), | ||||
number_format($lint)); | number_format($lint)); | ||||
} | } | ||||
if ($coverage !== null) { | |||||
$return['coverage'] = id(new DiffusionCoverageBarView()) | |||||
->setIsDirectory($coverage['is_dir']) | |||||
->setCovered($coverage['cov']) | |||||
->setUncovered($coverage['uncov']) | |||||
->setLargestNeighbor($coverage['largest']); | |||||
} | |||||
// The client treats these results as markup, so make sure they have been | // The client treats these results as markup, so make sure they have been | ||||
// escaped correctly. | // escaped correctly. | ||||
foreach ($return as $key => $value) { | foreach ($return as $key => $value) { | ||||
$return[$key] = hsprintf('%s', $value); | $return[$key] = hsprintf('%s', $value); | ||||
} | } | ||||
return $return; | return $return; | ||||
} | } | ||||
} | } |