Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/view/DiffusionPushLogListView.php
12242 views
1
<?php
2
3
final class DiffusionPushLogListView extends AphrontView {
4
5
private $logs;
6
7
public function setLogs(array $logs) {
8
assert_instances_of($logs, 'PhabricatorRepositoryPushLog');
9
$this->logs = $logs;
10
return $this;
11
}
12
13
public function render() {
14
$logs = $this->logs;
15
$viewer = $this->getViewer();
16
17
$reject_herald = PhabricatorRepositoryPushLog::REJECT_HERALD;
18
19
$handle_phids = array();
20
foreach ($logs as $log) {
21
$handle_phids[] = $log->getPusherPHID();
22
$device_phid = $log->getDevicePHID();
23
if ($device_phid) {
24
$handle_phids[] = $device_phid;
25
}
26
27
if ($log->getPushEvent()->getRejectCode() == $reject_herald) {
28
$handle_phids[] = $log->getPushEvent()->getRejectDetails();
29
}
30
}
31
32
$viewer->loadHandles($handle_phids);
33
34
// Only administrators can view remote addresses.
35
$remotes_visible = $viewer->getIsAdmin();
36
37
$flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames();
38
$reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames();
39
40
$rows = array();
41
$any_host = false;
42
foreach ($logs as $log) {
43
$repository = $log->getRepository();
44
$event = $log->getPushEvent();
45
46
if ($remotes_visible) {
47
$remote_address = $event->getRemoteAddress();
48
} else {
49
$remote_address = null;
50
}
51
52
$event_id = $log->getPushEvent()->getID();
53
54
$old_ref_link = null;
55
if ($log->getRefOld() != DiffusionCommitHookEngine::EMPTY_HASH) {
56
$old_ref_link = phutil_tag(
57
'a',
58
array(
59
'href' => $repository->getCommitURI($log->getRefOld()),
60
),
61
$log->getRefOldShort());
62
}
63
64
$device_phid = $log->getDevicePHID();
65
if ($device_phid) {
66
$device = $viewer->renderHandle($device_phid);
67
$any_host = true;
68
} else {
69
$device = null;
70
}
71
72
$flags = $log->getChangeFlags();
73
$flag_names = array();
74
foreach ($flag_map as $flag_key => $flag_name) {
75
if (($flags & $flag_key) === $flag_key) {
76
$flag_names[] = $flag_name;
77
}
78
}
79
$flag_names = phutil_implode_html(
80
phutil_tag('br'),
81
$flag_names);
82
83
$reject_code = $event->getRejectCode();
84
85
if ($reject_code == $reject_herald) {
86
$rule_phid = $event->getRejectDetails();
87
$handle = $viewer->renderHandle($rule_phid);
88
$reject_label = pht('Blocked: %s', $handle);
89
} else {
90
$reject_label = idx(
91
$reject_map,
92
$reject_code,
93
pht('Unknown ("%s")', $reject_code));
94
}
95
96
$host_wait = $this->formatMicroseconds($event->getHostWait());
97
$write_wait = $this->formatMicroseconds($event->getWriteWait());
98
$read_wait = $this->formatMicroseconds($event->getReadWait());
99
$hook_wait = $this->formatMicroseconds($event->getHookWait());
100
101
$rows[] = array(
102
phutil_tag(
103
'a',
104
array(
105
'href' => '/diffusion/pushlog/view/'.$event_id.'/',
106
),
107
$event_id),
108
phutil_tag(
109
'a',
110
array(
111
'href' => $repository->getURI(),
112
),
113
$repository->getDisplayName()),
114
$viewer->renderHandle($log->getPusherPHID()),
115
$remote_address,
116
$event->getRemoteProtocol(),
117
$device,
118
$log->getRefType(),
119
$log->getRefName(),
120
$old_ref_link,
121
phutil_tag(
122
'a',
123
array(
124
'href' => $repository->getCommitURI($log->getRefNew()),
125
),
126
$log->getRefNewShort()),
127
$flag_names,
128
$reject_label,
129
$viewer->formatShortDateTime($log->getEpoch()),
130
$host_wait,
131
$write_wait,
132
$read_wait,
133
$hook_wait,
134
);
135
}
136
137
$table = id(new AphrontTableView($rows))
138
->setHeaders(
139
array(
140
pht('Push'),
141
pht('Repository'),
142
pht('Pusher'),
143
pht('From'),
144
pht('Via'),
145
pht('Host'),
146
pht('Type'),
147
pht('Name'),
148
pht('Old'),
149
pht('New'),
150
pht('Flags'),
151
pht('Result'),
152
pht('Date'),
153
pht('Host Wait'),
154
pht('Write Wait'),
155
pht('Read Wait'),
156
pht('Hook Wait'),
157
))
158
->setColumnClasses(
159
array(
160
'',
161
'',
162
'',
163
'',
164
'',
165
'',
166
'',
167
'wide',
168
'n',
169
'n',
170
'',
171
'',
172
'right',
173
'n right',
174
'n right',
175
'n right',
176
'n right',
177
))
178
->setColumnVisibility(
179
array(
180
true,
181
true,
182
true,
183
$remotes_visible,
184
true,
185
$any_host,
186
));
187
188
return $table;
189
}
190
191
private function formatMicroseconds($duration) {
192
if ($duration === null) {
193
return null;
194
}
195
196
return pht('%sus', new PhutilNumber($duration));
197
}
198
199
}
200
201