Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/engineextension/DiffusionHovercardEngineExtension.php
12242 views
1
<?php
2
3
final class DiffusionHovercardEngineExtension
4
extends PhabricatorHovercardEngineExtension {
5
6
const EXTENSIONKEY = 'diffusion';
7
8
public function isExtensionEnabled() {
9
return PhabricatorApplication::isClassInstalled(
10
'PhabricatorDiffusionApplication');
11
}
12
13
public function getExtensionName() {
14
return pht('Diffusion Commits');
15
}
16
17
public function canRenderObjectHovercard($object) {
18
return ($object instanceof PhabricatorRepositoryCommit);
19
}
20
21
public function renderHovercard(
22
PHUIHovercardView $hovercard,
23
PhabricatorObjectHandle $handle,
24
$commit,
25
$data) {
26
27
$viewer = $this->getViewer();
28
29
$commit = id(new DiffusionCommitQuery())
30
->setViewer($viewer)
31
->needIdentities(true)
32
->needCommitData(true)
33
->withPHIDs(array($commit->getPHID()))
34
->executeOne();
35
if (!$commit) {
36
return;
37
}
38
39
$author_phid = $commit->getAuthorDisplayPHID();
40
$committer_phid = $commit->getCommitterDisplayPHID();
41
$repository_phid = $commit->getRepository()->getPHID();
42
43
$phids = array();
44
$phids[] = $author_phid;
45
$phids[] = $committer_phid;
46
$phids[] = $repository_phid;
47
48
$handles = $viewer->loadHandles($phids);
49
50
$hovercard->setTitle($handle->getName());
51
52
// See T13620. Use a longer slice of the message than the "summary" here,
53
// since we have at least a few lines of room in the UI.
54
$commit_message = $commit->getCommitMessageForDisplay();
55
56
$message_limit = 512;
57
58
$short_message = id(new PhutilUTF8StringTruncator())
59
->setMaximumBytes($message_limit * 4)
60
->setMaximumGlyphs($message_limit)
61
->truncateString($commit_message);
62
$short_message = phutil_escape_html_newlines($short_message);
63
64
$hovercard->setDetail($short_message);
65
66
$repository = $handles[$repository_phid]->renderLink();
67
$hovercard->addField(pht('Repository'), $repository);
68
69
$author = $handles[$author_phid]->renderLink();
70
if ($author_phid) {
71
$hovercard->addField(pht('Author'), $author);
72
}
73
74
if ($committer_phid && ($committer_phid !== $author_phid)) {
75
$committer = $handles[$committer_phid]->renderLink();
76
$hovercard->addField(pht('Committer'), $committer);
77
}
78
79
$date = phabricator_date($commit->getEpoch(), $viewer);
80
$hovercard->addField(pht('Commit Date'), $date);
81
82
if (!$commit->isAuditStatusNoAudit()) {
83
$status = $commit->getAuditStatusObject();
84
85
$hovercard->addField(
86
pht('Audit Status'),
87
$status->getName());
88
}
89
}
90
91
}
92
93