Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/customfield/DifferentialBranchField.php
12256 views
1
<?php
2
3
final class DifferentialBranchField
4
extends DifferentialCustomField {
5
6
public function getFieldKey() {
7
return 'differential:branch';
8
}
9
10
public function getFieldName() {
11
return pht('Branch');
12
}
13
14
public function getFieldDescription() {
15
return pht('Shows the branch a diff came from.');
16
}
17
18
public function shouldAppearInPropertyView() {
19
return true;
20
}
21
22
public function renderPropertyViewValue(array $handles) {
23
return null;
24
}
25
26
public function shouldAppearInDiffPropertyView() {
27
return true;
28
}
29
30
public function renderDiffPropertyViewLabel(DifferentialDiff $diff) {
31
return $this->getFieldName();
32
}
33
34
public function renderDiffPropertyViewValue(DifferentialDiff $diff) {
35
return $this->getBranchDescription($diff);
36
}
37
38
private function getBranchDescription(DifferentialDiff $diff) {
39
$branch = $diff->getBranch();
40
$bookmark = $diff->getBookmark();
41
42
if ($branch === null) {
43
$branch = '';
44
}
45
if ($bookmark === null) {
46
$bookmark = '';
47
}
48
49
if (strlen($branch) && strlen($bookmark)) {
50
return pht('%s (bookmark) on %s (branch)', $bookmark, $branch);
51
} else if (strlen($bookmark)) {
52
return pht('%s (bookmark)', $bookmark);
53
} else if (strlen($branch)) {
54
$onto = $diff->loadTargetBranch();
55
if ($onto !== null && strlen($onto) && ($onto !== $branch)) {
56
return pht(
57
'%s (branched from %s)',
58
$branch,
59
$onto);
60
} else {
61
return $branch;
62
}
63
} else {
64
return null;
65
}
66
}
67
68
public function getProTips() {
69
return array(
70
pht(
71
'In Git and Mercurial, use a branch like "%s" to automatically '.
72
'associate changes with the corresponding task.',
73
'T123'),
74
);
75
}
76
77
public function shouldAppearInTransactionMail() {
78
return true;
79
}
80
81
public function updateTransactionMailBody(
82
PhabricatorMetaMTAMailBody $body,
83
PhabricatorApplicationTransactionEditor $editor,
84
array $xactions) {
85
86
$revision = $this->getObject();
87
88
// Show the "BRANCH" section only if there's a new diff or the revision
89
// is "Accepted".
90
$is_update = (bool)$editor->getDiffUpdateTransaction($xactions);
91
$is_accepted = $revision->isAccepted();
92
if (!$is_update && !$is_accepted) {
93
return;
94
}
95
96
$branch = $this->getBranchDescription($revision->getActiveDiff());
97
if ($branch === null) {
98
return;
99
}
100
101
$body->addTextSection(pht('BRANCH'), $branch);
102
}
103
104
}
105
106