@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Integrate Pholio with Herald

Summary: Ref T2766. Does the integration via ApplicationTransactionsEditor. Only did addCC and Flag for proof of concept.

Test Plan: Made a rule to cc, made a rule to flag. They worked! (will attach screens to diff)

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T2766

Differential Revision: https://secure.phabricator.com/D6766

+211
+2
src/__phutil_library_map__.php
··· 613 613 'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php', 614 614 'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php', 615 615 'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php', 616 + 'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php', 616 617 'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php', 617 618 'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php', 618 619 'HeraldRule' => 'applications/herald/storage/HeraldRule.php', ··· 2627 2628 'HeraldInvalidFieldException' => 'Exception', 2628 2629 'HeraldNewController' => 'HeraldController', 2629 2630 'HeraldPHIDTypeRule' => 'PhabricatorPHIDType', 2631 + 'HeraldPholioMockAdapter' => 'HeraldAdapter', 2630 2632 'HeraldRecursiveConditionsException' => 'Exception', 2631 2633 'HeraldRule' => 2632 2634 array(
+3
src/applications/herald/adapter/HeraldAdapter.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group herald 5 + */ 3 6 abstract class HeraldAdapter { 4 7 5 8 const FIELD_TITLE = 'title';
+3
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group herald 5 + */ 3 6 final class HeraldCommitAdapter extends HeraldAdapter { 4 7 5 8 const FIELD_NEED_AUDIT_FOR_PACKAGE = 'need-audit-for-package';
+3
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group herald 5 + */ 3 6 final class HeraldDifferentialRevisionAdapter extends HeraldAdapter { 4 7 5 8 protected $revision;
+115
src/applications/herald/adapter/HeraldPholioMockAdapter.php
··· 1 + <?php 2 + 3 + /** 4 + * @group herald 5 + */ 6 + final class HeraldPholioMockAdapter extends HeraldAdapter { 7 + 8 + private $mock; 9 + private $ccPHIDs = array(); 10 + 11 + public function setMock(PholioMock $mock) { 12 + $this->mock = $mock; 13 + return $this; 14 + } 15 + public function getMock() { 16 + return $this->mock; 17 + } 18 + 19 + private function setCcPHIDs(array $cc_phids) { 20 + $this->ccPHIDs = $cc_phids; 21 + return $this; 22 + } 23 + public function getCcPHIDs() { 24 + return $this->ccPHIDs; 25 + } 26 + 27 + public function getAdapterContentName() { 28 + return pht('Pholio Mocks'); 29 + } 30 + 31 + public function getFields() { 32 + return array( 33 + self::FIELD_TITLE, 34 + self::FIELD_BODY, 35 + self::FIELD_AUTHOR, 36 + self::FIELD_CC, 37 + ); 38 + } 39 + 40 + public function getActions($rule_type) { 41 + switch ($rule_type) { 42 + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 43 + return array( 44 + self::ACTION_ADD_CC, 45 + self::ACTION_NOTHING, 46 + ); 47 + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 48 + return array( 49 + self::ACTION_ADD_CC, 50 + self::ACTION_FLAG, 51 + self::ACTION_NOTHING, 52 + ); 53 + } 54 + } 55 + 56 + public function getPHID() { 57 + return $this->getMock()->getPHID(); 58 + } 59 + 60 + public function getHeraldName() { 61 + return 'M'.$this->getMock()->getID(); 62 + } 63 + 64 + public function getHeraldField($field) { 65 + switch ($field) { 66 + case self::FIELD_TITLE: 67 + return $this->getMock()->getName(); 68 + case self::FIELD_BODY: 69 + return $this->getMock()->getDescription(); 70 + case self::FIELD_AUTHOR: 71 + return $this->getMock()->getAuthorPHID(); 72 + case self::FIELD_CC: 73 + return PhabricatorSubscribersQuery::loadSubscribersForPHID( 74 + $this->getMock()->getPHID()); 75 + } 76 + 77 + return parent::getHeraldField($field); 78 + } 79 + 80 + public function applyHeraldEffects(array $effects) { 81 + assert_instances_of($effects, 'HeraldEffect'); 82 + 83 + $result = array(); 84 + foreach ($effects as $effect) { 85 + $action = $effect->getAction(); 86 + switch ($action) { 87 + case self::ACTION_NOTHING: 88 + $result[] = new HeraldApplyTranscript( 89 + $effect, 90 + true, 91 + pht('Great success at doing nothing.')); 92 + break; 93 + case self::ACTION_ADD_CC: 94 + $add_cc = array(); 95 + foreach ($effect->getTarget() as $phid) { 96 + $add_cc[$phid] = true; 97 + } 98 + $this->setCcPHIDs(array_keys($add_cc)); 99 + $result[] = new HeraldApplyTranscript( 100 + $effect, 101 + true, 102 + pht('Added address to cc list.')); 103 + break; 104 + case self::ACTION_FLAG: 105 + $result[] = parent::applyFlagEffect( 106 + $effect, 107 + $this->getMock()->getPHID()); 108 + break; 109 + default: 110 + throw new Exception("No rules to handle action '{$action}'."); 111 + } 112 + } 113 + return $result; 114 + } 115 + }
+27
src/applications/pholio/editor/PholioMockEditor.php
··· 383 383 return true; 384 384 } 385 385 386 + protected function supportsHerald() { 387 + return true; 388 + } 389 + 390 + protected function buildHeraldAdapter( 391 + PhabricatorLiskDAO $object, 392 + array $xactions) { 393 + 394 + return id(new HeraldPholioMockAdapter()) 395 + ->setMock($object); 396 + } 397 + 398 + protected function didApplyHeraldRules( 399 + PhabricatorLiskDAO $object, 400 + HeraldAdapter $adapter, 401 + HeraldTranscript $transcript) { 402 + 403 + $cc_phids = $adapter->getCcPHIDs(); 404 + if ($cc_phids) { 405 + id(new PhabricatorSubscriptionsEditor()) 406 + ->setObject($object) 407 + ->setActor($this->requireActor()) 408 + ->subscribeImplicit($cc_phids) 409 + ->save(); 410 + } 411 + } 412 + 386 413 protected function sortTransactions(array $xactions) { 387 414 $head = array(); 388 415 $tail = array();
+58
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 16 16 private $mentionedPHIDs; 17 17 private $continueOnNoEffect; 18 18 private $parentMessageID; 19 + private $heraldAdapter; 20 + private $heraldTranscript; 19 21 private $subscribers; 20 22 21 23 private $isPreview; ··· 437 439 438 440 foreach ($xactions as $xaction) { 439 441 $this->applyExternalEffects($object, $xaction); 442 + } 443 + 444 + if ($this->supportsHerald()) { 445 + $this->applyHeraldRules($object, $xactions); 440 446 } 441 447 442 448 $this->applyFinalEffects($object, $xactions); ··· 1321 1327 */ 1322 1328 protected function supportsSearch() { 1323 1329 return false; 1330 + } 1331 + 1332 + 1333 + /* -( Herald Integration )-------------------------------------------------- */ 1334 + 1335 + 1336 + protected function supportsHerald() { 1337 + return false; 1338 + } 1339 + 1340 + protected function buildHeraldAdapter( 1341 + PhabricatorLiskDAO $object, 1342 + array $xactions) { 1343 + throw new Exception('No herald adapter specified.'); 1344 + } 1345 + 1346 + private function setHeraldAdapter(HeraldAdapter $adapter) { 1347 + $this->heraldAdapter = $adapter; 1348 + return $this; 1349 + } 1350 + 1351 + protected function getHeraldAdapter() { 1352 + return $this->heraldAdapter; 1353 + } 1354 + 1355 + private function setHeraldTranscript(HeraldTranscript $transcript) { 1356 + $this->heraldTranscript = $transcript; 1357 + return $this; 1358 + } 1359 + 1360 + protected function getHeraldTranscript() { 1361 + return $this->heraldTranscript; 1362 + } 1363 + 1364 + private function applyHeraldRules( 1365 + PhabricatorLiskDAO $object, 1366 + array $xactions) { 1367 + 1368 + $adapter = $this->buildHeraldAdapter($object, $xactions); 1369 + $xscript = HeraldEngine::loadAndApplyRules($adapter); 1370 + 1371 + $this->setHeraldAdapter($adapter); 1372 + $this->setHeraldTranscript($xscript); 1373 + 1374 + $this->didApplyHeraldRules($object, $adapter, $xscript); 1375 + } 1376 + 1377 + protected function didApplyHeraldRules( 1378 + PhabricatorLiskDAO $object, 1379 + HeraldAdapter $adapter, 1380 + HeraldTranscript $transcript) { 1381 + 1324 1382 } 1325 1383 1326 1384