@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 HeraldWebhookTestController
4 extends HeraldWebhookController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8
9 $hook = id(new HeraldWebhookQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($request->getURIData('id')))
12 ->requireCapabilities(
13 array(
14 PhabricatorPolicyCapability::CAN_VIEW,
15 PhabricatorPolicyCapability::CAN_EDIT,
16 ))
17 ->executeOne();
18 if (!$hook) {
19 return new Aphront404Response();
20 }
21
22 $v_object = null;
23 $e_object = null;
24 $errors = array();
25 if ($request->isFormPost()) {
26
27 $v_object = $request->getStr('object');
28 if (!strlen($v_object)) {
29 $object = $hook;
30 } else {
31 $objects = id(new PhabricatorObjectQuery())
32 ->setViewer($viewer)
33 ->withNames(array($v_object))
34 ->execute();
35 if ($objects) {
36 $object = head($objects);
37 } else {
38 $e_object = pht('Invalid');
39 $errors[] = pht('Specified object could not be loaded.');
40 }
41 }
42
43 if (!$errors) {
44 $xaction_query =
45 PhabricatorApplicationTransactionQuery::newQueryForObject($object);
46
47 $xactions = $xaction_query
48 ->withObjectPHIDs(array($object->getPHID()))
49 ->setViewer($viewer)
50 ->setLimit(10)
51 ->execute();
52
53 $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook)
54 ->setObjectPHID($object->getPHID())
55 ->setTriggerPHIDs(array($viewer->getPHID()))
56 ->setIsTestAction(true)
57 ->setTransactionPHIDs(mpull($xactions, 'getPHID'))
58 ->save();
59
60 $request->queueCall();
61
62 $next_uri = $hook->getURI().'request/'.$request->getID().'/';
63
64 return id(new AphrontRedirectResponse())->setURI($next_uri);
65 }
66 }
67
68 $instructions = <<<EOREMARKUP
69Optionally, choose an object to generate test data for (like `D123` or `T234`).
70
71The 10 most recent transactions for the object will be submitted to the webhook.
72EOREMARKUP;
73
74 $form = id(new AphrontFormView())
75 ->setViewer($viewer)
76 ->appendControl(
77 id(new AphrontFormTextControl())
78 ->setLabel(pht('Object'))
79 ->setName('object')
80 ->setError($e_object)
81 ->setValue($v_object));
82
83 return $this->newDialog()
84 ->setErrors($errors)
85 ->setWidth(AphrontDialogView::WIDTH_FORM)
86 ->setTitle(pht('New Test Request'))
87 ->appendParagraph(new PHUIRemarkupView($viewer, $instructions))
88 ->appendForm($form)
89 ->addCancelButton($hook->getURI())
90 ->addSubmitButton(pht('Test Webhook'));
91 }
92
93
94}