From 545dad319ec04b39cd2ca2cf6f11cb51d633f20c Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 18 Jan 2017 09:37:42 -0800 Subject: [PATCH] Add an "Auditors" rule for Commits Summary: Fixes T5889. You can't write a rule like "if no other Herald rules did anything...", but you can use this rule to check for Owners or an explicit "Auditors" field doing things. Test Plan: Using the test console, ran an "Auditors" rule against a commit with and without an auditor. Got expected pass/fail outcomes. Reviewers: chad Reviewed By: chad Maniphest Tasks: T5889 Differential Revision: https://secure.phabricator.com/D17221 --- src/__phutil_library_map__.php | 2 + .../DiffusionCommitAuditorsHeraldField.php | 41 +++++++++++++++++++ .../PhabricatorRepositoryAuditRequest.php | 13 ++++++ 3 files changed, 56 insertions(+) create mode 100644 src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1e1ae93e85..7d5031e3dd 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -617,6 +617,7 @@ phutil_register_library_map(array( 'DiffusionCommitActionTransaction' => 'applications/diffusion/xaction/DiffusionCommitActionTransaction.php', 'DiffusionCommitAffectedFilesHeraldField' => 'applications/diffusion/herald/DiffusionCommitAffectedFilesHeraldField.php', 'DiffusionCommitAuditTransaction' => 'applications/diffusion/xaction/DiffusionCommitAuditTransaction.php', + 'DiffusionCommitAuditorsHeraldField' => 'applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php', 'DiffusionCommitAuditorsTransaction' => 'applications/diffusion/xaction/DiffusionCommitAuditorsTransaction.php', 'DiffusionCommitAuthorHeraldField' => 'applications/diffusion/herald/DiffusionCommitAuthorHeraldField.php', 'DiffusionCommitAutocloseHeraldField' => 'applications/diffusion/herald/DiffusionCommitAutocloseHeraldField.php', @@ -5321,6 +5322,7 @@ phutil_register_library_map(array( 'DiffusionCommitActionTransaction' => 'DiffusionCommitTransactionType', 'DiffusionCommitAffectedFilesHeraldField' => 'DiffusionCommitHeraldField', 'DiffusionCommitAuditTransaction' => 'DiffusionCommitActionTransaction', + 'DiffusionCommitAuditorsHeraldField' => 'DiffusionCommitHeraldField', 'DiffusionCommitAuditorsTransaction' => 'DiffusionCommitTransactionType', 'DiffusionCommitAuthorHeraldField' => 'DiffusionCommitHeraldField', 'DiffusionCommitAutocloseHeraldField' => 'DiffusionCommitHeraldField', diff --git a/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php new file mode 100644 index 0000000000..8deee3417e --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionCommitAuditorsHeraldField.php @@ -0,0 +1,41 @@ +setViewer($viewer) + ->withPHIDs(array($object->getPHID())) + ->needAuditRequests(true) + ->executeOne(); + + $audits = $commit->getAudits(); + + $phids = array(); + foreach ($audits as $audit) { + if ($audit->isActiveAudit()) { + $phids[] = $audit->getAuditorPHID(); + } + } + + return $phids; + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID_LIST; + } + + protected function getDatasource() { + return new DiffusionAuditorDatasource(); + } + +} diff --git a/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php b/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php index f0a17718aa..ea86594d9e 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php +++ b/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php @@ -49,6 +49,19 @@ final class PhabricatorRepositoryAuditRequest return $this->assertAttached($this->commit); } + public function isActiveAudit() { + switch ($this->getAuditStatus()) { + case PhabricatorAuditStatusConstants::NONE: + case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED: + case PhabricatorAuditStatusConstants::RESIGNED: + case PhabricatorAuditStatusConstants::CLOSED: + case PhabricatorAuditStatusConstants::CC: + return false; + } + + return true; + } + public function isInteresting() { switch ($this->getAuditStatus()) { case PhabricatorAuditStatusConstants::NONE: