From b38449ce8f4ba84de8f30858cb74d11582ddcc76 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 21 Jan 2020 11:37:40 -0800 Subject: [PATCH] Implement an "Author's packages" Herald field for Differential Summary: Ref T13480. Add an "Author's packages" field to Herald to support writing rules like "if affected packages include X, and author's packages do not include X, raise the alarm". Test Plan: Wrote and executed rules with the field, saw a sensible field value in the transcript. Maniphest Tasks: T13480 Differential Revision: https://secure.phabricator.com/D20947 --- src/__phutil_library_map__.php | 2 ++ ...ntialRevisionAuthorPackagesHeraldField.php | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 718b33c822..b073642683 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -603,6 +603,7 @@ phutil_register_library_map(array( 'DifferentialRevisionActionTransaction' => 'applications/differential/xaction/DifferentialRevisionActionTransaction.php', 'DifferentialRevisionAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php', 'DifferentialRevisionAuthorHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorHeraldField.php', + 'DifferentialRevisionAuthorPackagesHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php', 'DifferentialRevisionAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php', 'DifferentialRevisionBuildableTransaction' => 'applications/differential/xaction/DifferentialRevisionBuildableTransaction.php', 'DifferentialRevisionCloseDetailsController' => 'applications/differential/controller/DifferentialRevisionCloseDetailsController.php', @@ -6595,6 +6596,7 @@ phutil_register_library_map(array( 'DifferentialRevisionActionTransaction' => 'DifferentialRevisionTransactionType', 'DifferentialRevisionAffectedFilesHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionAuthorHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionAuthorPackagesHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionAuthorProjectsHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionBuildableTransaction' => 'DifferentialRevisionTransactionType', 'DifferentialRevisionCloseDetailsController' => 'DifferentialController', diff --git a/src/applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php b/src/applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php new file mode 100644 index 0000000000..89a7df4cdb --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php @@ -0,0 +1,32 @@ +getAdapter(); + $viewer = $adapter->getViewer(); + + $packages = id(new PhabricatorOwnersPackageQuery()) + ->setViewer($viewer) + ->withAuthorityPHIDs(array($object->getAuthorPHID())) + ->execute(); + + return mpull($packages, 'getPHID'); + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID_LIST; + } + + protected function getDatasource() { + return new PhabricatorOwnersPackageDatasource(); + } + +}