2014-02-27 20:06:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialLintField
|
|
|
|
extends DifferentialCustomField {
|
|
|
|
|
|
|
|
public function getFieldKey() {
|
|
|
|
return 'differential:lint';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldName() {
|
|
|
|
return pht('Lint');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldDescription() {
|
|
|
|
return pht('Shows lint results.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAppearInPropertyView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-16 17:53:40 +02:00
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAppearInDiffPropertyView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderDiffPropertyViewLabel(DifferentialDiff $diff) {
|
2014-02-27 20:06:37 +01:00
|
|
|
return $this->getFieldName();
|
|
|
|
}
|
|
|
|
|
2015-06-16 17:53:40 +02:00
|
|
|
public function renderDiffPropertyViewValue(DifferentialDiff $diff) {
|
|
|
|
// TODO: This load is slightly inefficient, but most of this is moving
|
|
|
|
// to Harbormaster and this simplifies the transition. Eat 1-2 extra
|
|
|
|
// queries for now.
|
|
|
|
$keys = array(
|
2014-02-27 20:06:37 +01:00
|
|
|
'arc:lint',
|
|
|
|
'arc:lint-excuse',
|
|
|
|
);
|
|
|
|
|
2015-06-16 17:53:40 +02:00
|
|
|
$properties = id(new DifferentialDiffProperty())->loadAllWhere(
|
|
|
|
'diffID = %d AND name IN (%Ls)',
|
|
|
|
$diff->getID(),
|
|
|
|
$keys);
|
|
|
|
$properties = mpull($properties, 'getData', 'getName');
|
|
|
|
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$diff->attachProperty($key, idx($properties, $key));
|
|
|
|
}
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
$status = $this->renderLintStatus($diff);
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
$lint = array();
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-23 16:09:23 +02:00
|
|
|
$buildable = $diff->getBuildable();
|
|
|
|
if ($buildable) {
|
|
|
|
$target_phids = array();
|
|
|
|
foreach ($buildable->getBuilds() as $build) {
|
|
|
|
foreach ($build->getBuildTargets() as $target) {
|
|
|
|
$target_phids[] = $target->getPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$lint = id(new HarbormasterBuildLintMessage())->loadAllWhere(
|
|
|
|
'buildTargetPHID IN (%Ls) LIMIT 25',
|
|
|
|
$target_phids);
|
|
|
|
}
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
if (!$lint) {
|
|
|
|
// No Harbormaster messages, so look for legacy messages and make them
|
|
|
|
// look like modern messages.
|
|
|
|
$legacy_lint = $diff->getProperty('arc:lint');
|
|
|
|
if ($legacy_lint) {
|
|
|
|
// Show the top 100 legacy lint messages. Previously, we showed some
|
|
|
|
// by default and let the user toggle the rest. With modern messages,
|
|
|
|
// we can send the user to the Harbormaster detail page. Just show
|
|
|
|
// "a lot" of messages in legacy cases to try to strike a balance
|
|
|
|
// between implementation simplicitly and compatibility.
|
|
|
|
$legacy_lint = array_slice($legacy_lint, 0, 100);
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
$target = new HarbormasterBuildTarget();
|
|
|
|
foreach ($legacy_lint as $message) {
|
2015-06-21 19:37:55 +02:00
|
|
|
try {
|
|
|
|
$modern = HarbormasterBuildLintMessage::newFromDictionary(
|
|
|
|
$target,
|
|
|
|
$this->getModernLintMessageDictionary($message));
|
|
|
|
$lint[] = $modern;
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
// Ignore any poorly formatted messages.
|
|
|
|
}
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
if ($lint) {
|
|
|
|
$path_map = mpull($diff->loadChangesets(), 'getID', 'getFilename');
|
|
|
|
foreach ($path_map as $path => $id) {
|
|
|
|
$href = '#C'.$id.'NL';
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
// TODO: When the diff is not the right-hand-size diff, we should
|
|
|
|
// ideally adjust this URI to be absolute.
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
$path_map[$path] = $href;
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|
2015-06-21 19:11:53 +02:00
|
|
|
|
|
|
|
$view = id(new HarbormasterLintPropertyView())
|
|
|
|
->setPathURIMap($path_map)
|
|
|
|
->setLintMessages($lint);
|
|
|
|
} else {
|
|
|
|
$view = null;
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
return array(
|
|
|
|
$status,
|
|
|
|
$view,
|
|
|
|
);
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|
2014-03-09 21:18:17 +01:00
|
|
|
|
|
|
|
public function getWarningsForDetailView() {
|
|
|
|
$status = $this->getObject()->getActiveDiff()->getLintStatus();
|
|
|
|
if ($status < DifferentialLintStatus::LINT_WARN) {
|
|
|
|
return array();
|
|
|
|
}
|
2014-09-16 21:11:54 +02:00
|
|
|
if ($status == DifferentialLintStatus::LINT_AUTO_SKIP) {
|
|
|
|
return array();
|
|
|
|
}
|
2014-03-09 21:18:17 +01:00
|
|
|
|
|
|
|
$warnings = array();
|
|
|
|
if ($status == DifferentialLintStatus::LINT_SKIP) {
|
|
|
|
$warnings[] = pht(
|
|
|
|
'Lint was skipped when generating these changes.');
|
|
|
|
} else if ($status == DifferentialLintStatus::LINT_POSTPONED) {
|
|
|
|
$warnings[] = pht(
|
|
|
|
'Background linting has not finished executing on these changes.');
|
|
|
|
} else {
|
|
|
|
$warnings[] = pht('These changes have lint problems.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $warnings;
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
private function renderLintStatus(DifferentialDiff $diff) {
|
|
|
|
$colors = array(
|
|
|
|
DifferentialLintStatus::LINT_NONE => 'grey',
|
|
|
|
DifferentialLintStatus::LINT_OKAY => 'green',
|
|
|
|
DifferentialLintStatus::LINT_WARN => 'yellow',
|
|
|
|
DifferentialLintStatus::LINT_FAIL => 'red',
|
|
|
|
DifferentialLintStatus::LINT_SKIP => 'blue',
|
|
|
|
DifferentialLintStatus::LINT_AUTO_SKIP => 'blue',
|
|
|
|
DifferentialLintStatus::LINT_POSTPONED => 'blue',
|
|
|
|
);
|
|
|
|
$icon_color = idx($colors, $diff->getLintStatus(), 'grey');
|
|
|
|
|
|
|
|
$message = DifferentialRevisionUpdateHistoryView::getDiffLintMessage($diff);
|
|
|
|
|
|
|
|
$excuse = $diff->getProperty('arc:lint-excuse');
|
|
|
|
if (strlen($excuse)) {
|
|
|
|
$excuse = array(
|
|
|
|
phutil_tag('strong', array(), pht('Excuse:')),
|
|
|
|
' ',
|
|
|
|
phutil_escape_html_newlines($excuse),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = id(new PHUIStatusListView())
|
|
|
|
->addItem(
|
|
|
|
id(new PHUIStatusItemView())
|
|
|
|
->setIcon(PHUIStatusItemView::ICON_STAR, $icon_color)
|
|
|
|
->setTarget($message)
|
|
|
|
->setNote($excuse));
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getModernLintMessageDictionary(array $map) {
|
2015-06-21 19:37:55 +02:00
|
|
|
// Strip out `null` values to satisfy stricter typechecks.
|
|
|
|
foreach ($map as $key => $value) {
|
|
|
|
if ($value === null) {
|
|
|
|
unset($map[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:11:53 +02:00
|
|
|
// TODO: We might need to remap some stuff here?
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|