@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 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 if (!$this->getAdapter()->supportsWebhooks()) {
18 return false;
19 }
20
21 return true;
22 }
23
24 public function supportsRuleType($rule_type) {
25 return ($rule_type !== HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
26 }
27
28 public function applyEffect($object, HeraldEffect $effect) {
29 $adapter = $this->getAdapter();
30 $rule = $effect->getRule();
31 $target = $effect->getTarget();
32
33 foreach ($target as $webhook_phid) {
34 $adapter->queueWebhook($webhook_phid, $rule->getPHID());
35 }
36
37 $this->logEffect(self::DO_WEBHOOK, $target);
38 }
39
40 public function getHeraldActionStandardType() {
41 return self::STANDARD_PHID_LIST;
42 }
43
44 protected function getActionEffectMap() {
45 return array(
46 self::DO_WEBHOOK => array(
47 'icon' => 'fa-cloud-upload',
48 'color' => 'green',
49 'name' => pht('Called Webhooks'),
50 ),
51 );
52 }
53
54 public function renderActionDescription($value) {
55 return pht('Call webhooks: %s.', $this->renderHandleList($value));
56 }
57
58 protected function renderActionEffectDescription($type, $data) {
59 return pht('Called webhooks: %s.', $this->renderHandleList($data));
60 }
61
62 protected function getDatasource() {
63 return new HeraldWebhookDatasource();
64 }
65
66 public function getPHIDsAffectedByAction(HeraldActionRecord $record) {
67 return $record->getTarget();
68 }
69
70}