diff --git a/src/applications/audit/editor/PhabricatorAuditEditor.php b/src/applications/audit/editor/PhabricatorAuditEditor.php index f9524084a0..a6ef866c93 100644 --- a/src/applications/audit/editor/PhabricatorAuditEditor.php +++ b/src/applications/audit/editor/PhabricatorAuditEditor.php @@ -886,9 +886,8 @@ final class PhabricatorAuditEditor protected function buildHeraldAdapter( PhabricatorLiskDAO $object, array $xactions) { - return id(new HeraldCommitAdapter()) - ->setCommit($object); + ->setObject($object); } protected function didApplyHeraldRules( diff --git a/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php b/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php index 2aed146cbf..53fd62fe23 100644 --- a/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php @@ -29,7 +29,7 @@ final class HeraldDifferentialRevisionAdapter 'Test rules which run when a revision is created or updated.'); } - public function newTestAdapter($object) { + public function newTestAdapter(PhabricatorUser $viewer, $object) { return self::newLegacyAdapter( $object, $object->loadActiveDiff()); diff --git a/src/applications/diffusion/herald/HeraldCommitAdapter.php b/src/applications/diffusion/herald/HeraldCommitAdapter.php index 759b8afa6f..7b4d26b77c 100644 --- a/src/applications/diffusion/herald/HeraldCommitAdapter.php +++ b/src/applications/diffusion/herald/HeraldCommitAdapter.php @@ -8,7 +8,6 @@ final class HeraldCommitAdapter protected $revision; protected $commit; - protected $commitData; private $commitDiff; protected $affectedPaths; @@ -35,6 +34,23 @@ final class HeraldCommitAdapter 'Test rules which run after a commit is discovered and imported.'); } + public function newTestAdapter(PhabricatorUser $viewer, $object) { + $object = id(new DiffusionCommitQuery()) + ->setViewer($viewer) + ->withPHIDs(array($object->getPHID())) + ->needCommitData(true) + ->executeOne(); + if (!$object) { + throw new Exception( + pht( + 'Failed to reload commit ("%s") to fetch commit data.', + $object->getPHID())); + } + + return id(clone $this) + ->setObject($object); + } + protected function initializeNewAdapter() { $this->commit = $this->newObject(); } @@ -100,33 +116,6 @@ final class HeraldCommitAdapter return pht('This rule can trigger for **repositories** and **projects**.'); } - public function setCommit(PhabricatorRepositoryCommit $commit) { - $viewer = PhabricatorUser::getOmnipotentUser(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->withIDs(array($commit->getRepositoryID())) - ->executeOne(); - if (!$repository) { - throw new Exception(pht('Unable to load repository!')); - } - - $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( - 'commitID = %d', - $commit->getID()); - if (!$data) { - throw new Exception(pht('Unable to load commit data!')); - } - - $this->commit = clone $commit; - $this->commit->attachRepository($repository); - $this->commit->attachCommitData($data); - - $this->commitData = $data; - - return $this; - } - public function getHeraldName() { return $this->commit->getMonogram(); } @@ -171,7 +160,10 @@ final class HeraldCommitAdapter public function loadDifferentialRevision() { if ($this->affectedRevision === null) { $this->affectedRevision = false; - $data = $this->commitData; + + $commit = $this->getObject(); + $data = $commit->getCommitData(); + $revision_id = $data->getCommitDetail('differential.revisionID'); if ($revision_id) { // NOTE: The Herald rule owner might not actually have access to diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index ac227819f9..78ce862945 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -224,7 +224,7 @@ abstract class HeraldAdapter extends Phobject { return $this->isTestAdapterForObject($object); } - public function newTestAdapter($object) { + public function newTestAdapter(PhabricatorUser $viewer, $object) { return id(clone $this) ->setObject($object); } diff --git a/src/applications/herald/controller/HeraldTestConsoleController.php b/src/applications/herald/controller/HeraldTestConsoleController.php index fae92864f1..21bedcd848 100644 --- a/src/applications/herald/controller/HeraldTestConsoleController.php +++ b/src/applications/herald/controller/HeraldTestConsoleController.php @@ -142,7 +142,9 @@ final class HeraldTestConsoleController extends HeraldController { if ($request->isFormPost() && $adapter_key) { if (isset($can_select[$adapter_key])) { - $adapter = $can_select[$adapter_key]->newTestAdapter($object); + $adapter = $can_select[$adapter_key]->newTestAdapter( + $viewer, + $object); $this->setTestAdapter($adapter); return null; }