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

In Webhooks, give errors human-readable labels and show reminder text for "Silent Mode"

Summary:
Depends on D19928. See <https://discourse.phabricator-community.org/t/firehose-webhook-not-working-with-self-hosted-requestbin-instance/2240/>.

Currently, we report "hook" and "silent", which are raw internal codes.

Instead, report human-readable labels so the user gets a better hint about what's going on ("In Silent Mode").

Also, render a "hey, you're in silent mode so none of this will work" reminder banner in this UI.

Test Plan:
{F6074421}

Note:

- New warning banner.
- Table has more human-readable text ("In Silent Mode").

Reviewers: amckinley

Reviewed By: amckinley

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

+88 -9
+13
src/applications/herald/controller/HeraldWebhookViewController.php
··· 50 50 ->setLimit(20) 51 51 ->execute(); 52 52 53 + $warnings = array(); 54 + if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { 55 + $message = pht( 56 + 'Phabricator is currently configured in silent mode, so it will not '. 57 + 'publish webhooks. To adjust this setting, see '. 58 + '@{config:phabricator.silent} in Config.'); 59 + 60 + $warnings[] = id(new PHUIInfoView()) 61 + ->setTitle(pht('Silent Mode')) 62 + ->setSeverity(PHUIInfoView::SEVERITY_WARNING) 63 + ->appendChild(new PHUIRemarkupView($viewer, $message)); 64 + } 65 + 53 66 $requests_table = id(new HeraldWebhookRequestListView()) 54 67 ->setViewer($viewer) 55 68 ->setRequests($requests)
+53
src/applications/herald/storage/HeraldWebhookRequest.php
··· 26 26 const RESULT_OKAY = 'okay'; 27 27 const RESULT_FAIL = 'fail'; 28 28 29 + const ERRORTYPE_HOOK = 'hook'; 30 + const ERRORTYPE_HTTP = 'http'; 31 + const ERRORTYPE_TIMEOUT = 'timeout'; 32 + 33 + const ERROR_SILENT = 'silent'; 34 + const ERROR_DISABLED = 'disabled'; 35 + const ERROR_URI = 'uri'; 36 + const ERROR_OBJECT = 'object'; 37 + 29 38 protected function getConfiguration() { 30 39 return array( 31 40 self::CONFIG_AUX_PHID => true, ··· 108 117 return $this->getProperty('errorCode'); 109 118 } 110 119 120 + public function getErrorTypeForDisplay() { 121 + $map = array( 122 + self::ERRORTYPE_HOOK => pht('Hook Error'), 123 + self::ERRORTYPE_HTTP => pht('HTTP Error'), 124 + self::ERRORTYPE_TIMEOUT => pht('Request Timeout'), 125 + ); 126 + 127 + $type = $this->getErrorType(); 128 + return idx($map, $type, $type); 129 + } 130 + 131 + public function getErrorCodeForDisplay() { 132 + $code = $this->getErrorCode(); 133 + 134 + if ($this->getErrorType() !== self::ERRORTYPE_HOOK) { 135 + return $code; 136 + } 137 + 138 + $spec = $this->getHookErrorSpec($code); 139 + return idx($spec, 'display', $code); 140 + } 141 + 111 142 public function setTransactionPHIDs(array $phids) { 112 143 return $this->setProperty('transactionPHIDs', $phids); 113 144 } ··· 185 216 return id(new PHUIIconView()) 186 217 ->setIcon($icon, $color) 187 218 ->setTooltip($tooltip); 219 + } 220 + 221 + private function getHookErrorSpec($code) { 222 + $map = $this->getHookErrorMap(); 223 + return idx($map, $code, array()); 224 + } 225 + 226 + private function getHookErrorMap() { 227 + return array( 228 + self::ERROR_SILENT => array( 229 + 'display' => pht('In Silent Mode'), 230 + ), 231 + self::ERROR_DISABLED => array( 232 + 'display' => pht('Hook Disabled'), 233 + ), 234 + self::ERROR_URI => array( 235 + 'display' => pht('Invalid URI'), 236 + ), 237 + self::ERROR_OBJECT => array( 238 + 'display' => pht('Invalid Object'), 239 + ), 240 + ); 188 241 } 189 242 190 243
+3 -3
src/applications/herald/view/HeraldWebhookRequestListView.php
··· 55 55 $request->getID(), 56 56 $icon, 57 57 $handles[$request->getObjectPHID()]->renderLink(), 58 - $request->getErrorType(), 59 - $request->getErrorCode(), 58 + $request->getErrorTypeForDisplay(), 59 + $request->getErrorCodeForDisplay(), 60 60 $last_request, 61 61 ); 62 62 } ··· 66 66 ->setHeaders( 67 67 array( 68 68 pht('ID'), 69 - '', 69 + null, 70 70 pht('Object'), 71 71 pht('Type'), 72 72 pht('Code'),
+19 -6
src/applications/herald/worker/HeraldWebhookWorker.php
··· 35 35 // If we're in silent mode, permanently fail the webhook request and then 36 36 // return to complete this task. 37 37 if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { 38 - $this->failRequest($request, 'hook', 'silent'); 38 + $this->failRequest( 39 + $request, 40 + HeraldWebhookRequest::ERRORTYPE_HOOK, 41 + HeraldWebhookRequest::ERROR_SILENT); 39 42 return; 40 43 } 41 44 42 45 $hook = $request->getWebhook(); 43 46 44 47 if ($hook->isDisabled()) { 45 - $this->failRequest($request, 'hook', 'disabled'); 48 + $this->failRequest( 49 + $request, 50 + HeraldWebhookRequest::ERRORTYPE_HOOK, 51 + HeraldWebhookRequest::ERROR_DISABLED); 46 52 throw new PhabricatorWorkerPermanentFailureException( 47 53 pht( 48 54 'Associated hook ("%s") for webhook request ("%s") is disabled.', ··· 59 65 'https', 60 66 )); 61 67 } catch (Exception $ex) { 62 - $this->failRequest($request, 'hook', 'uri'); 68 + $this->failRequest( 69 + $request, 70 + HeraldWebhookRequest::ERRORTYPE_HOOK, 71 + HeraldWebhookRequest::ERROR_URI); 63 72 throw new PhabricatorWorkerPermanentFailureException( 64 73 pht( 65 74 'Associated hook ("%s") for webhook request ("%s") has invalid '. ··· 76 85 ->withPHIDs(array($object_phid)) 77 86 ->executeOne(); 78 87 if (!$object) { 79 - $this->failRequest($request, 'hook', 'object'); 88 + $this->failRequest( 89 + $request, 90 + HeraldWebhookRequest::ERRORTYPE_HOOK, 91 + HeraldWebhookRequest::ERROR_OBJECT); 92 + 80 93 throw new PhabricatorWorkerPermanentFailureException( 81 94 pht( 82 95 'Unable to load object ("%s") for webhook request ("%s").', ··· 182 195 list($status) = $future->resolve(); 183 196 184 197 if ($status->isTimeout()) { 185 - $error_type = 'timeout'; 198 + $error_type = HeraldWebhookRequest::ERRORTYPE_TIMEOUT; 186 199 } else { 187 - $error_type = 'http'; 200 + $error_type = HeraldWebhookRequest::ERRORTYPE_HTTP; 188 201 } 189 202 $error_code = $status->getStatusCode(); 190 203