Differential D13850 Diff 33455 src/applications/differential/controller/DifferentialChangesetViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialChangesetViewController.php
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | if ($left) { | ||||
$right_data); | $right_data); | ||||
$choice = clone nonempty($left, $right); | $choice = clone nonempty($left, $right); | ||||
$choice->attachHunks($synthetic->getHunks()); | $choice->attachHunks($synthetic->getHunks()); | ||||
$changeset = $choice; | $changeset = $choice; | ||||
} | } | ||||
$coverage = null; | if ($left_new || $right_new) { | ||||
if ($right && $right->getDiffID()) { | $diff_map = array(); | ||||
$unit = id(new DifferentialDiffProperty())->loadOneWhere( | if ($left) { | ||||
'diffID = %d AND name = %s', | $diff_map[] = $left->getDiff(); | ||||
$right->getDiffID(), | |||||
'arc:unit'); | |||||
if ($unit) { | |||||
$coverage = array(); | |||||
foreach ($unit->getData() as $result) { | |||||
$result_coverage = idx($result, 'coverage'); | |||||
if (!$result_coverage) { | |||||
continue; | |||||
} | |||||
$file_coverage = idx($result_coverage, $right->getFileName()); | |||||
if (!$file_coverage) { | |||||
continue; | |||||
} | } | ||||
$coverage[] = $file_coverage; | if ($right) { | ||||
$diff_map[] = $right->getDiff(); | |||||
} | } | ||||
$diff_map = mpull($diff_map, null, 'getPHID'); | |||||
$coverage = ArcanistUnitTestResult::mergeCoverage($coverage); | $buildables = id(new HarbormasterBuildableQuery()) | ||||
->setViewer($viewer) | |||||
->withBuildablePHIDs(array_keys($diff_map)) | |||||
->withManualBuildables(false) | |||||
->needBuilds(true) | |||||
->needTargets(true) | |||||
->execute(); | |||||
$buildables = mpull($buildables, null, 'getBuildablePHID'); | |||||
foreach ($diff_map as $diff_phid => $changeset_diff) { | |||||
$changeset_diff->attachBuildable(idx($buildables, $diff_phid)); | |||||
} | } | ||||
} | } | ||||
$coverage = null; | |||||
if ($right_new) { | |||||
$coverage = $this->loadCoverage($right); | |||||
} | |||||
$spec = $request->getStr('range'); | $spec = $request->getStr('range'); | ||||
list($range_s, $range_e, $mask) = | list($range_s, $range_e, $mask) = | ||||
DifferentialChangesetParser::parseRangeSpecification($spec); | DifferentialChangesetParser::parseRangeSpecification($spec); | ||||
$parser = id(new DifferentialChangesetParser()) | $parser = id(new DifferentialChangesetParser()) | ||||
->setCoverage($coverage) | ->setCoverage($coverage) | ||||
->setChangeset($changeset) | ->setChangeset($changeset) | ||||
->setRenderingReference($rendering_reference) | ->setRenderingReference($rendering_reference) | ||||
Show All 35 Lines | if ($revision) { | ||||
$inlines, | $inlines, | ||||
$old, | $old, | ||||
$new, | $new, | ||||
$revision); | $revision); | ||||
} else { | } else { | ||||
$inlines = array(); | $inlines = array(); | ||||
} | } | ||||
if ($left_new || $right_new) { | |||||
$diff_map = array(); | |||||
if ($left) { | |||||
$diff_map[] = $left->getDiff(); | |||||
} | |||||
if ($right) { | |||||
$diff_map[] = $right->getDiff(); | |||||
} | |||||
$diff_map = mpull($diff_map, null, 'getPHID'); | |||||
$buildables = id(new HarbormasterBuildableQuery()) | |||||
->setViewer($viewer) | |||||
->withBuildablePHIDs(array_keys($diff_map)) | |||||
->withManualBuildables(false) | |||||
->needBuilds(true) | |||||
->needTargets(true) | |||||
->execute(); | |||||
$buildables = mpull($buildables, null, 'getBuildablePHID'); | |||||
foreach ($diff_map as $diff_phid => $changeset_diff) { | |||||
$changeset_diff->attachBuildable(idx($buildables, $diff_phid)); | |||||
} | |||||
} | |||||
if ($left_new) { | if ($left_new) { | ||||
$inlines = array_merge( | $inlines = array_merge( | ||||
$inlines, | $inlines, | ||||
$this->buildLintInlineComments($left)); | $this->buildLintInlineComments($left)); | ||||
} | } | ||||
if ($right_new) { | if ($right_new) { | ||||
$inlines = array_merge( | $inlines = array_merge( | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | private function buildRawFileResponse( | ||||
} | } | ||||
return $file->getRedirectResponse(); | return $file->getRedirectResponse(); | ||||
} | } | ||||
private function buildLintInlineComments($changeset) { | private function buildLintInlineComments($changeset) { | ||||
$diff = $changeset->getDiff(); | $diff = $changeset->getDiff(); | ||||
$buildable = $diff->getBuildable(); | $target_phids = $diff->getBuildTargetPHIDs(); | ||||
if (!$buildable) { | |||||
return array(); | |||||
} | |||||
$target_phids = array(); | |||||
foreach ($buildable->getBuilds() as $build) { | |||||
foreach ($build->getBuildTargets() as $target) { | |||||
$target_phids[] = $target->getPHID(); | |||||
} | |||||
} | |||||
if (!$target_phids) { | if (!$target_phids) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$messages = id(new HarbormasterBuildLintMessage())->loadAllWhere( | $messages = id(new HarbormasterBuildLintMessage())->loadAllWhere( | ||||
'buildTargetPHID IN (%Ls) AND path = %s', | 'buildTargetPHID IN (%Ls) AND path = %s', | ||||
$target_phids, | $target_phids, | ||||
$changeset->getFilename()); | $changeset->getFilename()); | ||||
Show All 16 Lines | foreach ($messages as $message) { | ||||
->setSyntheticAuthor(pht('Lint: %s', $message->getName())) | ->setSyntheticAuthor(pht('Lint: %s', $message->getName())) | ||||
->setLineNumber($message->getLine()) | ->setLineNumber($message->getLine()) | ||||
->setContent($description); | ->setContent($description); | ||||
} | } | ||||
return $inlines; | return $inlines; | ||||
} | } | ||||
private function loadCoverage(DifferentialChangeset $changeset) { | |||||
$target_phids = $changeset->getDiff()->getBuildTargetPHIDs(); | |||||
if (!$target_phids) { | |||||
return array(); | |||||
} | |||||
$unit = id(new HarbormasterBuildUnitMessage())->loadAllWhere( | |||||
'buildTargetPHID IN (%Ls)', | |||||
$target_phids); | |||||
$coverage = array(); | |||||
foreach ($unit as $message) { | |||||
$test_coverage = $message->getProperty('coverage', array()); | |||||
$coverage_data = idx($test_coverage, $changeset->getFileName()); | |||||
if (!strlen($coverage_data)) { | |||||
continue; | |||||
} | |||||
$coverage[] = $coverage_data; | |||||
} | |||||
return ArcanistUnitTestResult::mergeCoverage($coverage); | |||||
} | |||||
} | } |