@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+12 -24
+12 -24
src/applications/diffusion/herald/HeraldCommitAdapter.php
··· 7 7 protected $diff; 8 8 protected $revision; 9 9 10 - protected $repository; 11 10 protected $commit; 12 11 protected $commitData; 13 12 private $commitDiff; ··· 42 41 43 42 public function setObject($object) { 44 43 $this->commit = $object; 44 + 45 45 return $this; 46 46 } 47 47 ··· 86 86 } 87 87 88 88 public function getTriggerObjectPHIDs() { 89 + $project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 90 + 89 91 return array_merge( 90 92 array( 91 - $this->repository->getPHID(), 93 + $this->getRepository()->getPHID(), 92 94 $this->getPHID(), 93 95 ), 94 - $this->repository->getProjectPHIDs()); 96 + $this->loadEdgePHIDs($project_type)); 95 97 } 96 98 97 99 public function explainValidTriggerObjects() { 98 100 return pht('This rule can trigger for **repositories** and **projects**.'); 99 101 } 100 102 101 - public static function newLegacyAdapter( 102 - PhabricatorRepository $repository, 103 - PhabricatorRepositoryCommit $commit, 104 - PhabricatorRepositoryCommitData $commit_data) { 105 - 106 - $object = new HeraldCommitAdapter(); 107 - 108 - $commit->attachRepository($repository); 109 - 110 - $object->repository = $repository; 111 - $object->commit = $commit; 112 - $object->commitData = $commit_data; 113 - 114 - return $object; 115 - } 116 - 117 103 public function setCommit(PhabricatorRepositoryCommit $commit) { 118 104 $viewer = PhabricatorUser::getOmnipotentUser(); 119 105 120 106 $repository = id(new PhabricatorRepositoryQuery()) 121 107 ->setViewer($viewer) 122 108 ->withIDs(array($commit->getRepositoryID())) 123 - ->needProjectPHIDs(true) 124 109 ->executeOne(); 125 110 if (!$repository) { 126 111 throw new Exception(pht('Unable to load repository!')); ··· 137 122 $this->commit->attachRepository($repository); 138 123 $this->commit->attachCommitData($data); 139 124 140 - $this->repository = $repository; 141 125 $this->commitData = $data; 142 126 143 127 return $this; ··· 150 134 public function loadAffectedPaths() { 151 135 if ($this->affectedPaths === null) { 152 136 $result = PhabricatorOwnerPathQuery::loadAffectedPaths( 153 - $this->repository, 137 + $this->getRepository(), 154 138 $this->commit, 155 139 PhabricatorUser::getOmnipotentUser()); 156 140 $this->affectedPaths = $result; ··· 161 145 public function loadAffectedPackages() { 162 146 if ($this->affectedPackages === null) { 163 147 $packages = PhabricatorOwnersPackage::loadAffectedPackages( 164 - $this->repository, 148 + $this->getRepository(), 165 149 $this->loadAffectedPaths()); 166 150 $this->affectedPackages = $packages; 167 151 } ··· 314 298 $drequest = DiffusionRequest::newFromDictionary( 315 299 array( 316 300 'user' => $viewer, 317 - 'repository' => $this->repository, 301 + 'repository' => $this->getRepository(), 318 302 'commit' => $this->commit->getCommitIdentifier(), 319 303 )); 320 304 ··· 323 307 $drequest, 324 308 $method, 325 309 $params); 310 + } 311 + 312 + private function getRepository() { 313 + return $this->getObject()->getRepository(); 326 314 } 327 315 328 316 /* -( HarbormasterBuildableAdapterInterface )------------------------------ */