From f659b8743a019ed3647454d1609dbc1d9ee27394 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 17 Aug 2016 08:34:59 -0700 Subject: [PATCH] Fix Herald test adapter for commits Summary: Fixes T11488. I broke this in D16360, I think by doing a little extra refactoring after testing it. This code is very old, before commits always needed to have repositories attached in order to do policy checks. Modernize it by mostly just using the repository which is present on the Commit object, and using the existing edge cache. Test Plan: Ran a commit through the Herald test adapter. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11488 Differential Revision: https://secure.phabricator.com/D16413 --- .../diffusion/herald/HeraldCommitAdapter.php | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/applications/diffusion/herald/HeraldCommitAdapter.php b/src/applications/diffusion/herald/HeraldCommitAdapter.php index 538753f669..bd34fe23cc 100644 --- a/src/applications/diffusion/herald/HeraldCommitAdapter.php +++ b/src/applications/diffusion/herald/HeraldCommitAdapter.php @@ -7,7 +7,6 @@ final class HeraldCommitAdapter protected $diff; protected $revision; - protected $repository; protected $commit; protected $commitData; private $commitDiff; @@ -42,6 +41,7 @@ final class HeraldCommitAdapter public function setObject($object) { $this->commit = $object; + return $this; } @@ -86,41 +86,26 @@ final class HeraldCommitAdapter } public function getTriggerObjectPHIDs() { + $project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; + return array_merge( array( - $this->repository->getPHID(), + $this->getRepository()->getPHID(), $this->getPHID(), ), - $this->repository->getProjectPHIDs()); + $this->loadEdgePHIDs($project_type)); } public function explainValidTriggerObjects() { return pht('This rule can trigger for **repositories** and **projects**.'); } - public static function newLegacyAdapter( - PhabricatorRepository $repository, - PhabricatorRepositoryCommit $commit, - PhabricatorRepositoryCommitData $commit_data) { - - $object = new HeraldCommitAdapter(); - - $commit->attachRepository($repository); - - $object->repository = $repository; - $object->commit = $commit; - $object->commitData = $commit_data; - - return $object; - } - public function setCommit(PhabricatorRepositoryCommit $commit) { $viewer = PhabricatorUser::getOmnipotentUser(); $repository = id(new PhabricatorRepositoryQuery()) ->setViewer($viewer) ->withIDs(array($commit->getRepositoryID())) - ->needProjectPHIDs(true) ->executeOne(); if (!$repository) { throw new Exception(pht('Unable to load repository!')); @@ -137,7 +122,6 @@ final class HeraldCommitAdapter $this->commit->attachRepository($repository); $this->commit->attachCommitData($data); - $this->repository = $repository; $this->commitData = $data; return $this; @@ -150,7 +134,7 @@ final class HeraldCommitAdapter public function loadAffectedPaths() { if ($this->affectedPaths === null) { $result = PhabricatorOwnerPathQuery::loadAffectedPaths( - $this->repository, + $this->getRepository(), $this->commit, PhabricatorUser::getOmnipotentUser()); $this->affectedPaths = $result; @@ -161,7 +145,7 @@ final class HeraldCommitAdapter public function loadAffectedPackages() { if ($this->affectedPackages === null) { $packages = PhabricatorOwnersPackage::loadAffectedPackages( - $this->repository, + $this->getRepository(), $this->loadAffectedPaths()); $this->affectedPackages = $packages; } @@ -314,7 +298,7 @@ final class HeraldCommitAdapter $drequest = DiffusionRequest::newFromDictionary( array( 'user' => $viewer, - 'repository' => $this->repository, + 'repository' => $this->getRepository(), 'commit' => $this->commit->getCommitIdentifier(), )); @@ -325,6 +309,10 @@ final class HeraldCommitAdapter $params); } + private function getRepository() { + return $this->getObject()->getRepository(); + } + /* -( HarbormasterBuildableAdapterInterface )------------------------------ */