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