Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/customfield/DifferentialHarbormasterField.php
12256 views
1
<?php
2
3
abstract class DifferentialHarbormasterField
4
extends DifferentialCustomField {
5
6
abstract protected function getDiffPropertyKeys();
7
abstract protected function loadHarbormasterTargetMessages(
8
array $target_phids);
9
abstract protected function getLegacyProperty();
10
abstract protected function newModernMessage(array $message);
11
abstract protected function renderHarbormasterStatus(
12
DifferentialDiff $diff,
13
array $messages);
14
abstract protected function newHarbormasterMessageView(array $messages);
15
16
public function renderDiffPropertyViewValue(DifferentialDiff $diff) {
17
// TODO: This load is slightly inefficient, but most of this is moving
18
// to Harbormaster and this simplifies the transition. Eat 1-2 extra
19
// queries for now.
20
$keys = $this->getDiffPropertyKeys();
21
22
$properties = id(new DifferentialDiffProperty())->loadAllWhere(
23
'diffID = %d AND name IN (%Ls)',
24
$diff->getID(),
25
$keys);
26
$properties = mpull($properties, 'getData', 'getName');
27
28
foreach ($keys as $key) {
29
$diff->attachProperty($key, idx($properties, $key));
30
}
31
32
$target_phids = $diff->getBuildTargetPHIDs();
33
if ($target_phids) {
34
$messages = $this->loadHarbormasterTargetMessages($target_phids);
35
} else {
36
$messages = array();
37
}
38
39
if (!$messages) {
40
// No Harbormaster messages, so look for legacy messages and make them
41
// look like modern messages.
42
$legacy_messages = $diff->getProperty($this->getLegacyProperty());
43
if ($legacy_messages) {
44
// Show the top 100 legacy lint messages. Previously, we showed some
45
// by default and let the user toggle the rest. With modern messages,
46
// we can send the user to the Harbormaster detail page. Just show
47
// "a lot" of messages in legacy cases to try to strike a balance
48
// between implementation simplicity and compatibility.
49
$legacy_messages = array_slice($legacy_messages, 0, 100);
50
51
foreach ($legacy_messages as $message) {
52
try {
53
$modern = $this->newModernMessage($message);
54
$messages[] = $modern;
55
} catch (Exception $ex) {
56
// Ignore any poorly formatted messages.
57
}
58
}
59
}
60
}
61
62
$status = $this->renderHarbormasterStatus($diff, $messages);
63
64
if ($messages) {
65
$path_map = mpull($diff->loadChangesets(), 'getID', 'getFilename');
66
foreach ($path_map as $path => $id) {
67
$href = '#C'.$id.'NL';
68
69
// TODO: When the diff is not the right-hand-size diff, we should
70
// ideally adjust this URI to be absolute.
71
72
$path_map[$path] = $href;
73
}
74
75
$view = $this->newHarbormasterMessageView($messages);
76
if ($view) {
77
$view->setPathURIMap($path_map);
78
}
79
} else {
80
$view = null;
81
}
82
83
if ($view) {
84
$view = phutil_tag(
85
'div',
86
array(
87
'class' => 'differential-harbormaster-table-view',
88
),
89
$view);
90
}
91
92
return array(
93
$status,
94
$view,
95
);
96
}
97
98
}
99
100