From 4b8a67ccde91ec25b930ee4e41b3682c8a39eda6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 12 Apr 2019 16:09:38 -0700 Subject: [PATCH] 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 --- .../20190412.herald.01.rebuild.php | 3 ++ ...iewersAddBlockingReviewersHeraldAction.php | 4 ++ ...ntialReviewersAddReviewersHeraldAction.php | 4 ++ ...ffusionAuditorsAddAuditorsHeraldAction.php | 4 ++ .../PhabricatorOwnersDetailController.php | 54 +++++++++++++++++++ ...ubscriptionsAddSubscribersHeraldAction.php | 4 ++ ...criptionsRemoveSubscribersHeraldAction.php | 4 ++ 7 files changed, 77 insertions(+) create mode 100644 resources/sql/autopatches/20190412.herald.01.rebuild.php diff --git a/resources/sql/autopatches/20190412.herald.01.rebuild.php b/resources/sql/autopatches/20190412.herald.01.rebuild.php new file mode 100644 index 0000000000..a29b7d2f45 --- /dev/null +++ b/resources/sql/autopatches/20190412.herald.01.rebuild.php @@ -0,0 +1,3 @@ +renderHandleList($value)); } + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { + return $record->getTarget(); + } + } diff --git a/src/applications/differential/herald/DifferentialReviewersAddReviewersHeraldAction.php b/src/applications/differential/herald/DifferentialReviewersAddReviewersHeraldAction.php index d39a4370c5..60e64c750d 100644 --- a/src/applications/differential/herald/DifferentialReviewersAddReviewersHeraldAction.php +++ b/src/applications/differential/herald/DifferentialReviewersAddReviewersHeraldAction.php @@ -29,4 +29,8 @@ final class DifferentialReviewersAddReviewersHeraldAction return pht('Add reviewers: %s.', $this->renderHandleList($value)); } + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { + return $record->getTarget(); + } + } diff --git a/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php b/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php index 36b01b96f8..f895847d4a 100644 --- a/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php +++ b/src/applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php @@ -30,4 +30,8 @@ final class DiffusionAuditorsAddAuditorsHeraldAction return pht('Add auditors: %s.', $this->renderHandleList($value)); } + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { + return $record->getTarget(); + } + } diff --git a/src/applications/owners/controller/PhabricatorOwnersDetailController.php b/src/applications/owners/controller/PhabricatorOwnersDetailController.php index c458e4dbd1..3aace69074 100644 --- a/src/applications/owners/controller/PhabricatorOwnersDetailController.php +++ b/src/applications/owners/controller/PhabricatorOwnersDetailController.php @@ -144,6 +144,8 @@ final class PhabricatorOwnersDetailController $crumbs->addTextCrumb($package->getMonogram()); $crumbs->setBorder(true); + $rules_view = $this->newRulesView($package); + $timeline = $this->buildTransactionTimeline( $package, new PhabricatorOwnersPackageTransactionQuery()); @@ -154,6 +156,7 @@ final class PhabricatorOwnersDetailController ->setCurtain($curtain) ->setMainColumn(array( $this->renderPathsTable($paths, $repositories), + $rules_view, $commit_panels, $timeline, )) @@ -345,4 +348,55 @@ final class PhabricatorOwnersDetailController return $box; } + private function newRulesView(PhabricatorOwnersPackage $package) { + $viewer = $this->getViewer(); + + $limit = 10; + $rules = id(new HeraldRuleQuery()) + ->setViewer($viewer) + ->withDisabled(false) + ->withAffectedObjectPHIDs(array($package->getPHID())) + ->needValidateAuthors(true) + ->setLimit($limit + 1) + ->execute(); + + $more_results = (count($rules) > $limit); + $rules = array_slice($rules, 0, $limit); + + $list = id(new HeraldRuleListView()) + ->setViewer($viewer) + ->setRules($rules) + ->newObjectList(); + + $list->setNoDataString( + pht( + 'No active Herald rules add this package as an auditor, reviewer, '. + 'or subscriber.')); + + $more_href = new PhutilURI( + '/herald/', + array('affectedPHID' => $package->getPHID())); + + if ($more_results) { + $list->newTailButton() + ->setHref($more_href); + } + + $more_link = id(new PHUIButtonView()) + ->setTag('a') + ->setIcon('fa-list-ul') + ->setText(pht('View All Rules')) + ->setHref($more_href); + + $header = id(new PHUIHeaderView()) + ->setHeader(pht('Affected By Herald Rules')) + ->setHeaderIcon(id(new PhabricatorHeraldApplication())->getIcon()) + ->addActionLink($more_link); + + return id(new PHUIObjectBoxView()) + ->setHeader($header) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->appendChild($list); + } + } diff --git a/src/applications/subscriptions/herald/PhabricatorSubscriptionsAddSubscribersHeraldAction.php b/src/applications/subscriptions/herald/PhabricatorSubscriptionsAddSubscribersHeraldAction.php index 14f72d313a..3604d368fc 100644 --- a/src/applications/subscriptions/herald/PhabricatorSubscriptionsAddSubscribersHeraldAction.php +++ b/src/applications/subscriptions/herald/PhabricatorSubscriptionsAddSubscribersHeraldAction.php @@ -29,4 +29,8 @@ final class PhabricatorSubscriptionsAddSubscribersHeraldAction return pht('Add subscribers: %s.', $this->renderHandleList($value)); } + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { + return $record->getTarget(); + } + } diff --git a/src/applications/subscriptions/herald/PhabricatorSubscriptionsRemoveSubscribersHeraldAction.php b/src/applications/subscriptions/herald/PhabricatorSubscriptionsRemoveSubscribersHeraldAction.php index 67ece2cb72..7b55e6b5aa 100644 --- a/src/applications/subscriptions/herald/PhabricatorSubscriptionsRemoveSubscribersHeraldAction.php +++ b/src/applications/subscriptions/herald/PhabricatorSubscriptionsRemoveSubscribersHeraldAction.php @@ -29,4 +29,8 @@ final class PhabricatorSubscriptionsRemoveSubscribersHeraldAction return pht('Remove subscribers: %s.', $this->renderHandleList($value)); } + public function getPHIDsAffectedByAction(HeraldActionRecord $record) { + return $record->getTarget(); + } + }