@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

Index and show Owners packages affected by Herald rules

Summary:
Depends on D20412. See PHI1147.

- Index the targets of "Add Reviewer", "Add Blocking Reviewer", "Add Auditor", "Add Subscriber", and "Remove Subscriber" Herald rules. My major goal is to get Owners packages. This will also hit projects/users, but we just don't read those edges (for now, at least).
- Add a "Related Herald Rules" panel to Owners Package pages.
- Add a migration to reindex Herald rules for the recent build plan stuff and this, now that such a migration is easy to write.

Test Plan:
Ran migration, verified all rules reindexed.

{F6372695}

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

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

+77
+3
resources/sql/autopatches/20190412.herald.01.rebuild.php
··· 1 + <?php 2 + 3 + PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery('HeraldRuleQuery');
+4
src/applications/differential/herald/DifferentialReviewersAddBlockingReviewersHeraldAction.php
··· 29 29 return pht('Add blocking reviewers: %s.', $this->renderHandleList($value)); 30 30 } 31 31 32 + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { 33 + return $record->getTarget(); 34 + } 35 + 32 36 }
+4
src/applications/differential/herald/DifferentialReviewersAddReviewersHeraldAction.php
··· 29 29 return pht('Add reviewers: %s.', $this->renderHandleList($value)); 30 30 } 31 31 32 + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { 33 + return $record->getTarget(); 34 + } 35 + 32 36 }
+4
src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php
··· 30 30 return pht('Add auditors: %s.', $this->renderHandleList($value)); 31 31 } 32 32 33 + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { 34 + return $record->getTarget(); 35 + } 36 + 33 37 }
+54
src/applications/owners/controller/PhabricatorOwnersDetailController.php
··· 144 144 $crumbs->addTextCrumb($package->getMonogram()); 145 145 $crumbs->setBorder(true); 146 146 147 + $rules_view = $this->newRulesView($package); 148 + 147 149 $timeline = $this->buildTransactionTimeline( 148 150 $package, 149 151 new PhabricatorOwnersPackageTransactionQuery()); ··· 154 156 ->setCurtain($curtain) 155 157 ->setMainColumn(array( 156 158 $this->renderPathsTable($paths, $repositories), 159 + $rules_view, 157 160 $commit_panels, 158 161 $timeline, 159 162 )) ··· 343 346 ->setTable($table); 344 347 345 348 return $box; 349 + } 350 + 351 + private function newRulesView(PhabricatorOwnersPackage $package) { 352 + $viewer = $this->getViewer(); 353 + 354 + $limit = 10; 355 + $rules = id(new HeraldRuleQuery()) 356 + ->setViewer($viewer) 357 + ->withDisabled(false) 358 + ->withAffectedObjectPHIDs(array($package->getPHID())) 359 + ->needValidateAuthors(true) 360 + ->setLimit($limit + 1) 361 + ->execute(); 362 + 363 + $more_results = (count($rules) > $limit); 364 + $rules = array_slice($rules, 0, $limit); 365 + 366 + $list = id(new HeraldRuleListView()) 367 + ->setViewer($viewer) 368 + ->setRules($rules) 369 + ->newObjectList(); 370 + 371 + $list->setNoDataString( 372 + pht( 373 + 'No active Herald rules add this package as an auditor, reviewer, '. 374 + 'or subscriber.')); 375 + 376 + $more_href = new PhutilURI( 377 + '/herald/', 378 + array('affectedPHID' => $package->getPHID())); 379 + 380 + if ($more_results) { 381 + $list->newTailButton() 382 + ->setHref($more_href); 383 + } 384 + 385 + $more_link = id(new PHUIButtonView()) 386 + ->setTag('a') 387 + ->setIcon('fa-list-ul') 388 + ->setText(pht('View All Rules')) 389 + ->setHref($more_href); 390 + 391 + $header = id(new PHUIHeaderView()) 392 + ->setHeader(pht('Affected By Herald Rules')) 393 + ->setHeaderIcon(id(new PhabricatorHeraldApplication())->getIcon()) 394 + ->addActionLink($more_link); 395 + 396 + return id(new PHUIObjectBoxView()) 397 + ->setHeader($header) 398 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 399 + ->appendChild($list); 346 400 } 347 401 348 402 }
+4
src/applications/subscriptions/herald/PhabricatorSubscriptionsAddSubscribersHeraldAction.php
··· 29 29 return pht('Add subscribers: %s.', $this->renderHandleList($value)); 30 30 } 31 31 32 + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { 33 + return $record->getTarget(); 34 + } 35 + 32 36 }
+4
src/applications/subscriptions/herald/PhabricatorSubscriptionsRemoveSubscribersHeraldAction.php
··· 29 29 return pht('Remove subscribers: %s.', $this->renderHandleList($value)); 30 30 } 31 31 32 + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { 33 + return $record->getTarget(); 34 + } 35 + 32 36 }