1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30:56 +01:00

Read modern coverage information for tables of contents

Summary:
Ref T8096. This modernizes the last thing which was reading the old datasource.

Also fix a bug where it didn't work.

Test Plan: {F698405}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8096

Differential Revision: https://secure.phabricator.com/D13852
This commit is contained in:
epriestley 2015-08-10 15:24:15 -07:00
parent bcdb7e9a2c
commit 5485fb8aa9
5 changed files with 38 additions and 26 deletions

View file

@ -251,15 +251,19 @@ final class DifferentialChangesetViewController extends DifferentialController {
->setMask($mask); ->setMask($mask);
if ($request->isAjax()) { if ($request->isAjax()) {
// NOTE: We must render the changeset before we render coverage
// information, since it builds some caches.
$rendered_changeset = $parser->renderChangeset();
$mcov = $parser->renderModifiedCoverage(); $mcov = $parser->renderModifiedCoverage();
$coverage = array( $coverage_data = array(
'differential-mcoverage-'.md5($changeset->getFilename()) => $mcov, 'differential-mcoverage-'.md5($changeset->getFilename()) => $mcov,
); );
return id(new PhabricatorChangesetResponse()) return id(new PhabricatorChangesetResponse())
->setRenderedChangeset($parser->renderChangeset()) ->setRenderedChangeset($rendered_changeset)
->setCoverage($coverage) ->setCoverage($coverage_data)
->setUndoTemplates($parser->getRenderer()->renderUndoTemplates()); ->setUndoTemplates($parser->getRenderer()->renderUndoTemplates());
} }

View file

@ -108,7 +108,7 @@ final class DifferentialDiffViewController extends DifferentialController {
$table_of_contents = id(new DifferentialDiffTableOfContentsView()) $table_of_contents = id(new DifferentialDiffTableOfContentsView())
->setChangesets($changesets) ->setChangesets($changesets)
->setVisibleChangesets($changesets) ->setVisibleChangesets($changesets)
->setUnitTestData(idx($props, 'arc:unit', array())); ->setCoverageMap($diff->loadCoverageMap($viewer));
$refs = array(); $refs = array();
foreach ($changesets as $changeset) { foreach ($changesets as $changeset) {

View file

@ -353,7 +353,7 @@ final class DifferentialRevisionViewController extends DifferentialController {
$toc_view->setChangesets($changesets); $toc_view->setChangesets($changesets);
$toc_view->setVisibleChangesets($visible_changesets); $toc_view->setVisibleChangesets($visible_changesets);
$toc_view->setRenderingReferences($rendering_references); $toc_view->setRenderingReferences($rendering_references);
$toc_view->setUnitTestData(idx($props, 'arc:unit', array())); $toc_view->setCoverageMap($target->loadCoverageMap($user));
if ($repository) { if ($repository) {
$toc_view->setRepository($repository); $toc_view->setRepository($repository);
} }

View file

@ -348,6 +348,31 @@ final class DifferentialDiff
return $target_phids; return $target_phids;
} }
public function loadCoverageMap(PhabricatorUser $viewer) {
$target_phids = $this->getBuildTargetPHIDs();
if (!$target_phids) {
return array();
}
$unit = id(new HarbormasterBuildUnitMessage())->loadAllWhere(
'buildTargetPHID IN (%Ls)',
$target_phids);
$map = array();
foreach ($unit as $message) {
$coverage = $message->getProperty('coverage', array());
foreach ($coverage as $path => $coverage_data) {
$map[$path][] = $coverage_data;
}
}
foreach ($map as $path => $coverage_items) {
$map[$path] = ArcanistUnitTestResult::mergeCoverage($coverage_items);
}
return $map;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -10,7 +10,7 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
private $renderURI = '/differential/changeset/'; private $renderURI = '/differential/changeset/';
private $revisionID; private $revisionID;
private $whitespace; private $whitespace;
private $unitTestData; private $coverageMap;
public function setChangesets($changesets) { public function setChangesets($changesets) {
$this->changesets = $changesets; $this->changesets = $changesets;
@ -37,8 +37,8 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
return $this; return $this;
} }
public function setUnitTestData($unit_test_data) { public function setCoverageMap(array $coverage_map) {
$this->unitTestData = $unit_test_data; $this->coverageMap = $coverage_map;
return $this; return $this;
} }
@ -60,23 +60,6 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
$rows = array(); $rows = array();
$coverage = array();
if ($this->unitTestData) {
$coverage_by_file = array();
foreach ($this->unitTestData as $result) {
$test_coverage = idx($result, 'coverage');
if (!$test_coverage) {
continue;
}
foreach ($test_coverage as $file => $results) {
$coverage_by_file[$file][] = $results;
}
}
foreach ($coverage_by_file as $file => $coverages) {
$coverage[$file] = ArcanistUnitTestResult::mergeCoverage($coverages);
}
}
$changesets = $this->changesets; $changesets = $this->changesets;
$paths = array(); $paths = array();
foreach ($changesets as $id => $changeset) { foreach ($changesets as $id => $changeset) {
@ -144,7 +127,7 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
'M'); 'M');
$fname = $changeset->getFilename(); $fname = $changeset->getFilename();
$cov = $this->renderCoverage($coverage, $fname); $cov = $this->renderCoverage($this->coverageMap, $fname);
if ($cov === null) { if ($cov === null) {
$mcov = $cov = phutil_tag('em', array(), '-'); $mcov = $cov = phutil_tag('em', array(), '-');
} else { } else {