Skip to content

Commit 9e50967

Browse files
committed
Adds a "Release Branch" field to Differential
Summary: Our very first custom differential field, complete with Herald support. See https://secure.phabricator.com/book/phabricator/article/custom_fields/ for more information about custom fields in Phabricator. Over time we can improve on this; we can add a field for the corresponding dev version of the revision, we can add validation for this field to ensure the branch always exists, etc. For now, I'd like to keep the first cut of this as straightforward as possible. Test Plan: Start up a test Phabricator instance for development. To no one's surprise, I used a docker image to do this locally. See https://phab.trifacta.com/P38 for the details. Add the php file from this diff to the `phabricator/src/extensions/` folder. Note that this folder is gitignore'd, so future upgrades of Phabricator should remain seamless. Set up a test repository (find some old github repo you don't really care about any more (you don't even have to give Phabricator write access to it)) and try creating a diff for it. You'll see the "Release Branch" field show up when you `arc diff`. Add a Herald rule to take some action when the release branch matches some regexp. Try out your Herald rule by creating the differential revision. Reviewers: tan, arash, #tf-arc, zasgar, vihang Reviewed By: #tf-arc, zasgar, vihang Subscribers: alexras Differential Revision: https://phab.trifacta.com/D4969
1 parent db758b8 commit 9e50967

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed

DifferentialReleaseBranchField.php

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?php
2+
3+
final class DifferentialReleaseBranchField
4+
extends DifferentialStoredCustomField {
5+
6+
public function getFieldType() {
7+
return 'text';
8+
}
9+
10+
public function getFieldKey() {
11+
return 'trifacta:release-branch';
12+
}
13+
14+
public function getFieldKeyForConduit() {
15+
return 'releaseRevision';
16+
}
17+
18+
public function getFieldName() {
19+
return pht('Release Branch');
20+
}
21+
22+
public function getFieldDescription() {
23+
return pht('Indicates the intended branch for this revision.');
24+
}
25+
26+
public function getHeraldFieldValue() {
27+
return $this->getValue();
28+
}
29+
30+
public function shouldDisableByDefault() {
31+
return false;
32+
}
33+
34+
public function shouldAppearInPropertyView() {
35+
return true;
36+
}
37+
38+
public function renderPropertyViewLabel() {
39+
return $this->getFieldName();
40+
}
41+
42+
public function renderPropertyViewValue(array $handles) {
43+
return $this->getValue();
44+
}
45+
46+
public function shouldAppearInEditView() {
47+
return true;
48+
}
49+
50+
public function shouldAppearInApplicationTransactions() {
51+
return true;
52+
}
53+
54+
public function shouldAppearInCommitMessageTemplate() {
55+
return true;
56+
}
57+
58+
public function getOldValueForApplicationTransactions() {
59+
return $this->getValue();
60+
}
61+
62+
public function getNewValueForApplicationTransactions() {
63+
return $this->getValue();
64+
}
65+
66+
public function readValueFromRequest(AphrontRequest $request) {
67+
$this->setValue($request->getStr($this->getFieldKey()));
68+
}
69+
70+
public function renderEditControl(array $handles) {
71+
return id(new AphrontFormTextControl())
72+
->setName($this->getFieldKey())
73+
->setValue($this->getValue())
74+
->setLabel($this->getFieldName());
75+
}
76+
77+
public function getApplicationTransactionTitle(
78+
PhabricatorApplicationTransaction $xaction) {
79+
$author_phid = $xaction->getAuthorPHID();
80+
$old = $xaction->getOldValue();
81+
$new = $xaction->getNewValue();
82+
83+
return pht(
84+
'%s updated the release branch for this revision.',
85+
$xaction->renderHandleLink($author_phid));
86+
}
87+
88+
public function getApplicationTransactionTitleForFeed(
89+
PhabricatorApplicationTransaction $xaction) {
90+
91+
$object_phid = $xaction->getObjectPHID();
92+
$author_phid = $xaction->getAuthorPHID();
93+
$old = $xaction->getOldValue();
94+
$new = $xaction->getNewValue();
95+
96+
return pht(
97+
'%s updated the release branch for %s.',
98+
$xaction->renderHandleLink($author_phid),
99+
$xaction->renderHandleLink($object_phid));
100+
}
101+
102+
public function shouldAppearInCommitMessage() {
103+
return true;
104+
}
105+
106+
public function shouldAllowEditInCommitMessage() {
107+
return true;
108+
}
109+
110+
public function shouldOverwriteWhenCommitMessageIsEdited() {
111+
return true;
112+
}
113+
114+
public function getCommitMessageLabels() {
115+
return array(
116+
'Release Branch'
117+
);
118+
}
119+
120+
public function renderCommitMessageValue(array $handles) {
121+
return $this->getValue();
122+
}
123+
124+
public function shouldAppearInConduitDictionary() {
125+
return true;
126+
}
127+
128+
// Copied from phabricator/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php
129+
130+
public function buildFieldIndexes() {
131+
$indexes = array();
132+
133+
$value = $this->getFieldValue();
134+
if (strlen($value)) {
135+
$indexes[] = $this->newStringIndex($value);
136+
}
137+
138+
return $indexes;
139+
}
140+
141+
public function readApplicationSearchValueFromRequest(
142+
PhabricatorApplicationSearchEngine $engine,
143+
AphrontRequest $request) {
144+
145+
return $request->getStr($this->getFieldKey());
146+
}
147+
148+
public function applyApplicationSearchConstraintToQuery(
149+
PhabricatorApplicationSearchEngine $engine,
150+
PhabricatorCursorPagedPolicyAwareQuery $query,
151+
$value) {
152+
153+
if (strlen($value)) {
154+
$query->withApplicationSearchContainsConstraint(
155+
$this->newStringIndex(null),
156+
$value);
157+
}
158+
}
159+
160+
public function appendToApplicationSearchForm(
161+
PhabricatorApplicationSearchEngine $engine,
162+
AphrontFormView $form,
163+
$value) {
164+
165+
$form->appendChild(
166+
id(new AphrontFormTextControl())
167+
->setLabel($this->getFieldName())
168+
->setName($this->getFieldKey())
169+
->setValue($value));
170+
}
171+
172+
public function shouldAppearInHerald() {
173+
return true;
174+
}
175+
176+
public function getHeraldFieldConditions() {
177+
return array(
178+
HeraldAdapter::CONDITION_CONTAINS,
179+
HeraldAdapter::CONDITION_NOT_CONTAINS,
180+
HeraldAdapter::CONDITION_IS,
181+
HeraldAdapter::CONDITION_IS_NOT,
182+
HeraldAdapter::CONDITION_REGEXP,
183+
);
184+
}
185+
186+
public function readValueFromCommitMessage($value) {
187+
$this->setValue($value);
188+
return $this;
189+
}
190+
191+
}

0 commit comments

Comments
 (0)