From f713e1dfc160009a7ee0d1b2b73e0f9aff29e7d3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 16 Feb 2018 04:30:48 -0800 Subject: [PATCH] Add Owners Package support for "Commit Hook: Content" Herald rules Summary: See PHI370. Support the "Affected packages" and "Affected package owners" Herald fields in pre-commit hooks. I believe there's no technical reason these fields aren't supported and this was just overlooked. Test Plan: Wrote a rule which makes use of the new fields, pushed commits through it. Checked transcripts and saw sensible-looking values. Differential Revision: https://secure.phabricator.com/D19104 --- src/__phutil_library_map__.php | 4 +++ ...sionPreCommitContentPackageHeraldField.php | 29 ++++++++++++++++ ...reCommitContentPackageOwnerHeraldField.php | 34 +++++++++++++++++++ .../herald/HeraldPreCommitContentAdapter.php | 14 ++++++++ .../PhabricatorEmailFormatSettingsPanel.php | 5 ++- 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/applications/diffusion/herald/DiffusionPreCommitContentPackageHeraldField.php create mode 100644 src/applications/diffusion/herald/DiffusionPreCommitContentPackageOwnerHeraldField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f04f930863..c2ee4966c1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -812,6 +812,8 @@ phutil_register_library_map(array( 'DiffusionPreCommitContentHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentHeraldField.php', 'DiffusionPreCommitContentMergeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentMergeHeraldField.php', 'DiffusionPreCommitContentMessageHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentMessageHeraldField.php', + 'DiffusionPreCommitContentPackageHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPackageHeraldField.php', + 'DiffusionPreCommitContentPackageOwnerHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPackageOwnerHeraldField.php', 'DiffusionPreCommitContentPusherHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPusherHeraldField.php', 'DiffusionPreCommitContentPusherIsCommitterHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPusherIsCommitterHeraldField.php', 'DiffusionPreCommitContentPusherProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPusherProjectsHeraldField.php', @@ -6007,6 +6009,8 @@ phutil_register_library_map(array( 'DiffusionPreCommitContentHeraldField' => 'HeraldField', 'DiffusionPreCommitContentMergeHeraldField' => 'DiffusionPreCommitContentHeraldField', 'DiffusionPreCommitContentMessageHeraldField' => 'DiffusionPreCommitContentHeraldField', + 'DiffusionPreCommitContentPackageHeraldField' => 'DiffusionPreCommitContentHeraldField', + 'DiffusionPreCommitContentPackageOwnerHeraldField' => 'DiffusionPreCommitContentHeraldField', 'DiffusionPreCommitContentPusherHeraldField' => 'DiffusionPreCommitContentHeraldField', 'DiffusionPreCommitContentPusherIsCommitterHeraldField' => 'DiffusionPreCommitContentHeraldField', 'DiffusionPreCommitContentPusherProjectsHeraldField' => 'DiffusionPreCommitContentHeraldField', diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentPackageHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentPackageHeraldField.php new file mode 100644 index 0000000000..084d3b2d00 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentPackageHeraldField.php @@ -0,0 +1,29 @@ +getAdapter()->loadAffectedPackages(); + return mpull($packages, 'getPHID'); + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID_LIST; + } + + protected function getDatasource() { + return new PhabricatorOwnersPackageDatasource(); + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentPackageOwnerHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentPackageOwnerHeraldField.php new file mode 100644 index 0000000000..564ef36827 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentPackageOwnerHeraldField.php @@ -0,0 +1,34 @@ +getAdapter()->loadAffectedPackages(); + if (!$packages) { + return array(); + } + + $owners = PhabricatorOwnersOwner::loadAllForPackages($packages); + return mpull($owners, 'getUserPHID'); + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID_LIST; + } + + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); + } + +} diff --git a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php index c93ba32345..cee5f97419 100644 --- a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php +++ b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php @@ -7,6 +7,8 @@ final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter { private $fields; private $revision = false; + private $affectedPackages; + public function getAdapterContentName() { return pht('Commit Hook: Commit Content'); } @@ -223,4 +225,16 @@ final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter { $this->getObject()->getRefNew()); } + public function loadAffectedPackages() { + if ($this->affectedPackages === null) { + $packages = PhabricatorOwnersPackage::loadAffectedPackages( + $this->getHookEngine()->getRepository(), + $this->getDiffContent('name')); + $this->affectedPackages = $packages; + } + + return $this->affectedPackages; + } + + } diff --git a/src/applications/settings/panel/PhabricatorEmailFormatSettingsPanel.php b/src/applications/settings/panel/PhabricatorEmailFormatSettingsPanel.php index bdc3c994b3..51ff40ed9d 100644 --- a/src/applications/settings/panel/PhabricatorEmailFormatSettingsPanel.php +++ b/src/applications/settings/panel/PhabricatorEmailFormatSettingsPanel.php @@ -18,7 +18,9 @@ final class PhabricatorEmailFormatSettingsPanel } public function isManagementPanel() { - if (!$this->isUserPanel()) { + return false; +/* + if (!$this->isUserPanel()) { return false; } @@ -27,6 +29,7 @@ final class PhabricatorEmailFormatSettingsPanel } return false; +*/ } public function isTemplatePanel() {