forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiffusionRepositoryBranchesManagementPanel.php
135 lines (109 loc) · 3.58 KB
/
DiffusionRepositoryBranchesManagementPanel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
final class DiffusionRepositoryBranchesManagementPanel
extends DiffusionRepositoryManagementPanel {
const PANELKEY = 'branches';
public function getManagementPanelLabel() {
return pht('Branches');
}
public function getManagementPanelOrder() {
return 1000;
}
public function shouldEnableForRepository(
PhabricatorRepository $repository) {
return ($repository->isGit() || $repository->isHg());
}
public function getManagementPanelIcon() {
$repository = $this->getRepository();
$has_any =
$repository->getDetail('default-branch') ||
$repository->getFetchRules() ||
$repository->getTrackOnlyRules() ||
$repository->getPermanentRefRules();
if ($has_any) {
return 'fa-code-fork';
} else {
return 'fa-code-fork grey';
}
}
protected function getEditEngineFieldKeys() {
return array(
'defaultBranch',
'fetchRefs',
'permanentRefs',
'trackOnly',
);
}
public function buildManagementPanelCurtain() {
$repository = $this->getRepository();
$viewer = $this->getViewer();
$action_list = $this->newActionList();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$repository,
PhabricatorPolicyCapability::CAN_EDIT);
$branches_uri = $this->getEditPageURI();
$action_list->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Branches'))
->setHref($branches_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$drequest = DiffusionRequest::newFromDictionary(
array(
'user' => $viewer,
'repository' => $repository,
));
$view_uri = $drequest->generateURI(
array(
'action' => 'branches',
));
$action_list->addAction(
id(new PhabricatorActionView())
->setIcon('fa-code-fork')
->setName(pht('View Branches'))
->setHref($view_uri));
return $this->newCurtainView()
->setActionList($action_list);
}
public function buildManagementPanelContent() {
$repository = $this->getRepository();
$viewer = $this->getViewer();
$content = array();
$view = id(new PHUIPropertyListView())
->setViewer($viewer);
$default_branch = nonempty(
$repository->getDetail('default-branch'),
phutil_tag('em', array(), $repository->getDefaultBranch()));
$view->addProperty(pht('Default Branch'), $default_branch);
if ($repository->supportsFetchRules()) {
$fetch_only = $repository->getFetchRules();
if ($fetch_only) {
$fetch_display = implode(', ', $fetch_only);
} else {
$fetch_display = phutil_tag('em', array(), pht('Fetch All Refs'));
}
$view->addProperty(pht('Fetch Refs'), $fetch_display);
}
$track_only_rules = $repository->getTrackOnlyRules();
if ($track_only_rules) {
$track_only_rules = implode(', ', $track_only_rules);
$view->addProperty(pht('Track Only'), $track_only_rules);
}
$publishing_disabled = $repository->isPublishingDisabled();
if ($publishing_disabled) {
$permanent_display =
phutil_tag('em', array(), pht('Publishing Disabled'));
} else {
$permanent_rules = $repository->getPermanentRefRules();
if ($permanent_rules) {
$permanent_display = implode(', ', $permanent_rules);
} else {
$permanent_display = phutil_tag('em', array(), pht('All Branches'));
}
}
$view->addProperty(pht('Permanent Refs'), $permanent_display);
$content[] = $this->newBox(pht('Branches'), $view);
return $content;
}
}