3 final class ReleephRequestTransactionalEditor
4 extends PhabricatorApplicationTransactionEditor
{
6 public function getEditorApplicationClass() {
7 return 'PhabricatorReleephApplication';
10 public function getEditorObjectsDescription() {
11 return pht('Releeph Requests');
14 public function getTransactionTypes() {
15 $types = parent
::getTransactionTypes();
17 $types[] = PhabricatorTransactions
::TYPE_COMMENT
;
18 $types[] = ReleephRequestTransaction
::TYPE_COMMIT
;
19 $types[] = ReleephRequestTransaction
::TYPE_DISCOVERY
;
20 $types[] = ReleephRequestTransaction
::TYPE_EDIT_FIELD
;
21 $types[] = ReleephRequestTransaction
::TYPE_MANUAL_IN_BRANCH
;
22 $types[] = ReleephRequestTransaction
::TYPE_PICK_STATUS
;
23 $types[] = ReleephRequestTransaction
::TYPE_REQUEST
;
24 $types[] = ReleephRequestTransaction
::TYPE_USER_INTENT
;
29 protected function getCustomTransactionOldValue(
30 PhabricatorLiskDAO
$object,
31 PhabricatorApplicationTransaction
$xaction) {
33 switch ($xaction->getTransactionType()) {
34 case ReleephRequestTransaction
::TYPE_REQUEST
:
35 return $object->getRequestCommitPHID();
37 case ReleephRequestTransaction
::TYPE_EDIT_FIELD
:
38 $field = newv($xaction->getMetadataValue('fieldClass'), array());
39 $value = $field->setReleephRequest($object)->getValue();
42 case ReleephRequestTransaction
::TYPE_USER_INTENT
:
43 $user_phid = $xaction->getAuthorPHID();
44 return idx($object->getUserIntents(), $user_phid);
46 case ReleephRequestTransaction
::TYPE_PICK_STATUS
:
47 return (int)$object->getPickStatus();
50 case ReleephRequestTransaction
::TYPE_COMMIT
:
51 return $object->getCommitIdentifier();
53 case ReleephRequestTransaction
::TYPE_DISCOVERY
:
54 return $object->getCommitPHID();
56 case ReleephRequestTransaction
::TYPE_MANUAL_IN_BRANCH
:
57 return $object->getInBranch();
61 protected function getCustomTransactionNewValue(
62 PhabricatorLiskDAO
$object,
63 PhabricatorApplicationTransaction
$xaction) {
65 switch ($xaction->getTransactionType()) {
66 case ReleephRequestTransaction
::TYPE_REQUEST
:
67 case ReleephRequestTransaction
::TYPE_USER_INTENT
:
68 case ReleephRequestTransaction
::TYPE_EDIT_FIELD
:
69 case ReleephRequestTransaction
::TYPE_PICK_STATUS
:
70 case ReleephRequestTransaction
::TYPE_COMMIT
:
71 case ReleephRequestTransaction
::TYPE_DISCOVERY
:
72 case ReleephRequestTransaction
::TYPE_MANUAL_IN_BRANCH
:
73 return $xaction->getNewValue();
77 protected function applyCustomInternalTransaction(
78 PhabricatorLiskDAO
$object,
79 PhabricatorApplicationTransaction
$xaction) {
81 $new = $xaction->getNewValue();
83 switch ($xaction->getTransactionType()) {
84 case ReleephRequestTransaction
::TYPE_REQUEST
:
85 $object->setRequestCommitPHID($new);
88 case ReleephRequestTransaction
::TYPE_USER_INTENT
:
89 $user_phid = $xaction->getAuthorPHID();
90 $intents = $object->getUserIntents();
91 $intents[$user_phid] = $new;
92 $object->setUserIntents($intents);
95 case ReleephRequestTransaction
::TYPE_EDIT_FIELD
:
96 $field = newv($xaction->getMetadataValue('fieldClass'), array());
98 ->setReleephRequest($object)
102 case ReleephRequestTransaction
::TYPE_PICK_STATUS
:
103 $object->setPickStatus($new);
106 case ReleephRequestTransaction
::TYPE_COMMIT
:
107 $this->setInBranchFromAction($object, $xaction);
108 $object->setCommitIdentifier($new);
111 case ReleephRequestTransaction
::TYPE_DISCOVERY
:
112 $this->setInBranchFromAction($object, $xaction);
113 $object->setCommitPHID($new);
116 case ReleephRequestTransaction
::TYPE_MANUAL_IN_BRANCH
:
117 $object->setInBranch((int)$new);
122 protected function applyCustomExternalTransaction(
123 PhabricatorLiskDAO
$object,
124 PhabricatorApplicationTransaction
$xaction) {
129 protected function filterTransactions(
130 PhabricatorLiskDAO
$object,
133 // Remove TYPE_DISCOVERY xactions that are the result of a reparse.
134 $previously_discovered_commits = array();
135 $discovery_xactions = idx(
136 mgroup($xactions, 'getTransactionType'),
137 ReleephRequestTransaction
::TYPE_DISCOVERY
);
138 if ($discovery_xactions) {
139 $previous_xactions = id(new ReleephRequestTransactionQuery())
140 ->setViewer(PhabricatorUser
::getOmnipotentUser())
141 ->withObjectPHIDs(array($object->getPHID()))
144 foreach ($previous_xactions as $xaction) {
145 if ($xaction->getTransactionType() ===
146 ReleephRequestTransaction
::TYPE_DISCOVERY
) {
148 $commit_phid = $xaction->getNewValue();
149 $previously_discovered_commits[$commit_phid] = true;
154 foreach ($xactions as $key => $xaction) {
155 if ($xaction->getTransactionType() ===
156 ReleephRequestTransaction
::TYPE_DISCOVERY
&&
157 idx($previously_discovered_commits, $xaction->getNewValue())) {
159 unset($xactions[$key]);
163 return parent
::filterTransactions($object, $xactions);
166 protected function shouldSendMail(
167 PhabricatorLiskDAO
$object,
170 // Avoid sending emails that only talk about commit discovery.
171 $types = array_unique(mpull($xactions, 'getTransactionType'));
172 if ($types === array(ReleephRequestTransaction
::TYPE_DISCOVERY
)) {
176 // Don't email people when we discover that something picks or reverts OK.
177 if ($types === array(ReleephRequestTransaction
::TYPE_PICK_STATUS
)) {
178 if (!mfilter($xactions, 'isBoringPickStatus', true /* negate */)) {
179 // If we effectively call "isInterestingPickStatus" and get nothing...
187 protected function buildReplyHandler(PhabricatorLiskDAO
$object) {
188 return id(new ReleephRequestReplyHandler())
189 ->setActor($this->getActor())
190 ->setMailReceiver($object);
193 protected function getMailSubjectPrefix() {
197 protected function buildMailTemplate(PhabricatorLiskDAO
$object) {
198 $id = $object->getID();
199 $title = $object->getSummaryForDisplay();
200 return id(new PhabricatorMetaMTAMail())
201 ->setSubject("RQ{$id}: {$title}");
204 protected function getMailTo(PhabricatorLiskDAO
$object) {
207 $product = $object->getBranch()->getProduct();
208 foreach ($product->getPushers() as $phid) {
212 foreach ($object->getUserIntents() as $phid => $intent) {
219 protected function getMailCC(PhabricatorLiskDAO
$object) {
223 protected function buildMailBody(
224 PhabricatorLiskDAO
$object,
227 $body = parent
::buildMailBody($object, $xactions);
230 $releeph_branch = $rq->getBranch();
231 $releeph_project = $releeph_branch->getProduct();
234 * If any of the events we are emailing about were about a pick failure
235 * (and/or a revert failure?), include pick failure instructions.
237 $has_pick_failure = false;
238 foreach ($xactions as $xaction) {
239 if ($xaction->getTransactionType() ===
240 ReleephRequestTransaction
::TYPE_PICK_STATUS
&&
241 $xaction->getNewValue() === ReleephRequest
::PICK_FAILED
) {
243 $has_pick_failure = true;
247 if ($has_pick_failure) {
248 $instructions = $releeph_project->getDetail('pick_failure_instructions');
250 $body->addRemarkupSection(
251 pht('PICK FAILURE INSTRUCTIONS'),
256 $name = sprintf('RQ%s: %s', $rq->getID(), $rq->getSummaryForDisplay());
257 $body->addTextSection(
258 pht('RELEEPH REQUEST'),
260 PhabricatorEnv
::getProductionURI('/RQ'.$rq->getID()));
262 $project_and_branch = sprintf(
264 $releeph_project->getName(),
265 $releeph_branch->getDisplayNameWithDetail());
267 $body->addTextSection(
268 pht('RELEEPH BRANCH'),
269 $project_and_branch."\n".
270 PhabricatorEnv
::getProductionURI($releeph_branch->getURI()));
275 private function setInBranchFromAction(
277 ReleephRequestTransaction
$xaction) {
279 $action = $xaction->getMetadataValue('action');
291 $type = $xaction->getTransactionType();
292 $new = $xaction->getNewValue();
295 "Unknown discovery action '%s' for xaction of type %s ".
296 "with new value %s mentioning %s!",