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

Add a "Call webhooks" action to Herald

Summary: Depends on D19048. Fixes T11330.

Test Plan: Wrote rules to call webhooks selectively, saw them fire appropriately with correct trigger attribution.

Maniphest Tasks: T11330

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

+129
+4
src/__phutil_library_map__.php
··· 1357 1357 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 1358 1358 'HeraldBasicFieldGroup' => 'applications/herald/field/HeraldBasicFieldGroup.php', 1359 1359 'HeraldBuildableState' => 'applications/herald/state/HeraldBuildableState.php', 1360 + 'HeraldCallWebhookAction' => 'applications/herald/action/HeraldCallWebhookAction.php', 1360 1361 'HeraldCommentAction' => 'applications/herald/action/HeraldCommentAction.php', 1361 1362 'HeraldCommitAdapter' => 'applications/diffusion/herald/HeraldCommitAdapter.php', 1362 1363 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', ··· 1444 1445 'HeraldWebhook' => 'applications/herald/storage/HeraldWebhook.php', 1445 1446 'HeraldWebhookCallManagementWorkflow' => 'applications/herald/management/HeraldWebhookCallManagementWorkflow.php', 1446 1447 'HeraldWebhookController' => 'applications/herald/controller/HeraldWebhookController.php', 1448 + 'HeraldWebhookDatasource' => 'applications/herald/typeahead/HeraldWebhookDatasource.php', 1447 1449 'HeraldWebhookEditController' => 'applications/herald/controller/HeraldWebhookEditController.php', 1448 1450 'HeraldWebhookEditEngine' => 'applications/herald/editor/HeraldWebhookEditEngine.php', 1449 1451 'HeraldWebhookEditor' => 'applications/herald/editor/HeraldWebhookEditor.php', ··· 6631 6633 'HeraldApplyTranscript' => 'Phobject', 6632 6634 'HeraldBasicFieldGroup' => 'HeraldFieldGroup', 6633 6635 'HeraldBuildableState' => 'HeraldState', 6636 + 'HeraldCallWebhookAction' => 'HeraldAction', 6634 6637 'HeraldCommentAction' => 'HeraldAction', 6635 6638 'HeraldCommitAdapter' => array( 6636 6639 'HeraldAdapter', ··· 6741 6744 ), 6742 6745 'HeraldWebhookCallManagementWorkflow' => 'HeraldWebhookManagementWorkflow', 6743 6746 'HeraldWebhookController' => 'HeraldController', 6747 + 'HeraldWebhookDatasource' => 'PhabricatorTypeaheadDatasource', 6744 6748 'HeraldWebhookEditController' => 'HeraldWebhookController', 6745 6749 'HeraldWebhookEditEngine' => 'PhabricatorEditEngine', 6746 6750 'HeraldWebhookEditor' => 'PhabricatorApplicationTransactionEditor',
+62
src/applications/herald/action/HeraldCallWebhookAction.php
··· 1 + <?php 2 + 3 + final class HeraldCallWebhookAction extends HeraldAction { 4 + 5 + const ACTIONCONST = 'webhook'; 6 + const DO_WEBHOOK = 'do.call-webhook'; 7 + 8 + public function getHeraldActionName() { 9 + return pht('Call webhooks'); 10 + } 11 + 12 + public function getActionGroupKey() { 13 + return HeraldUtilityActionGroup::ACTIONGROUPKEY; 14 + } 15 + 16 + public function supportsObject($object) { 17 + return true; 18 + } 19 + 20 + public function supportsRuleType($rule_type) { 21 + return ($rule_type !== HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 22 + } 23 + 24 + public function applyEffect($object, HeraldEffect $effect) { 25 + $adapter = $this->getAdapter(); 26 + $rule = $effect->getRule(); 27 + $target = $effect->getTarget(); 28 + 29 + foreach ($target as $webhook_phid) { 30 + $adapter->queueWebhook($webhook_phid, $rule->getPHID()); 31 + } 32 + 33 + $this->logEffect(self::DO_WEBHOOK, $target); 34 + } 35 + 36 + public function getHeraldActionStandardType() { 37 + return self::STANDARD_PHID_LIST; 38 + } 39 + 40 + protected function getActionEffectMap() { 41 + return array( 42 + self::DO_WEBHOOK => array( 43 + 'icon' => 'fa-cloud-upload', 44 + 'color' => 'green', 45 + 'name' => pht('Called Webhooks'), 46 + ), 47 + ); 48 + } 49 + 50 + public function renderActionDescription($value) { 51 + return pht('Call webhooks: %s.', $this->renderHandleList($value)); 52 + } 53 + 54 + protected function renderActionEffectDescription($type, $data) { 55 + return pht('Called webhooks: %s.', $this->renderHandleList($data)); 56 + } 57 + 58 + protected function getDatasource() { 59 + return new HeraldWebhookDatasource(); 60 + } 61 + 62 + }
+14
src/applications/herald/adapter/HeraldAdapter.php
··· 41 41 private $viewer; 42 42 private $mustEncryptReasons = array(); 43 43 private $actingAsPHID; 44 + private $webhookMap = array(); 44 45 45 46 public function getEmailPHIDs() { 46 47 return array_values($this->emailPHIDs); ··· 1204 1205 1205 1206 final public function getMustEncryptReasons() { 1206 1207 return $this->mustEncryptReasons; 1208 + } 1209 + 1210 + 1211 + /* -( Webhooks )----------------------------------------------------------- */ 1212 + 1213 + 1214 + final public function queueWebhook($webhook_phid, $rule_phid) { 1215 + $this->webhookMap[$webhook_phid][] = $rule_phid; 1216 + return $this; 1217 + } 1218 + 1219 + final public function getWebhookMap() { 1220 + return $this->webhookMap; 1207 1221 } 1208 1222 1209 1223 }
+48
src/applications/herald/typeahead/HeraldWebhookDatasource.php
··· 1 + <?php 2 + 3 + final class HeraldWebhookDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getPlaceholderText() { 7 + return pht('Type a webhook name...'); 8 + } 9 + 10 + public function getBrowseTitle() { 11 + return pht('Browse Webhooks'); 12 + } 13 + 14 + public function getDatasourceApplicationClass() { 15 + return 'PhabricatorHeraldApplication'; 16 + } 17 + 18 + public function loadResults() { 19 + $viewer = $this->getViewer(); 20 + $raw_query = $this->getRawQuery(); 21 + 22 + $hooks = id(new HeraldWebhookQuery()) 23 + ->setViewer($viewer) 24 + ->execute(); 25 + 26 + $handles = id(new PhabricatorHandleQuery()) 27 + ->setViewer($viewer) 28 + ->withPHIDs(mpull($hooks, 'getPHID')) 29 + ->execute(); 30 + 31 + $results = array(); 32 + foreach ($hooks as $hook) { 33 + $handle = $handles[$hook->getPHID()]; 34 + 35 + $result = id(new PhabricatorTypeaheadResult()) 36 + ->setName($handle->getFullName()) 37 + ->setPHID($handle->getPHID()); 38 + 39 + if ($hook->isDisabled()) { 40 + $result->setClosed(pht('Disabled')); 41 + } 42 + 43 + $results[] = $result; 44 + } 45 + 46 + return $results; 47 + } 48 + }
+1
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 1156 1156 $adapter = $this->getHeraldAdapter(); 1157 1157 $this->heraldEmailPHIDs = $adapter->getEmailPHIDs(); 1158 1158 $this->heraldForcedEmailPHIDs = $adapter->getForcedEmailPHIDs(); 1159 + $this->webhookMap = $adapter->getWebhookMap(); 1159 1160 } 1160 1161 1161 1162 $xactions = $this->didApplyTransactions($object, $xactions);