@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.

Support "Repository's projects" field in Commit and Differential Revision rules

Summary: This also cleans up some code a little bit. Most of the gymnastics are to make sure we call `needProjectPHIDs()` appropriately.

Test Plan: Created new commit and revision rules with this field. Ran commits and revisions through the test console. Field behavior seemed correct.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, dctrwatson

Differential Revision: https://secure.phabricator.com/D7923

+74 -33
+42 -5
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 64 64 if ($object instanceof PhabricatorRepository) { 65 65 return true; 66 66 } 67 + if ($object instanceof PhabricatorProject) { 68 + return true; 69 + } 67 70 return false; 68 71 } 69 72 70 73 public function getTriggerObjectPHIDs() { 71 - return array( 72 - $this->repository->getPHID(), 73 - $this->getPHID(), 74 - ); 74 + return array_merge( 75 + array( 76 + $this->repository->getPHID(), 77 + $this->getPHID(), 78 + ), 79 + $this->repository->getProjectPHIDs()); 75 80 } 76 81 77 82 public function explainValidTriggerObjects() { 78 83 return pht( 79 - 'This rule can trigger for **repositories**.'); 84 + 'This rule can trigger for **repositories** and **projects**.'); 80 85 } 81 86 82 87 public function getFieldNameMap() { ··· 95 100 self::FIELD_COMMITTER, 96 101 self::FIELD_REVIEWER, 97 102 self::FIELD_REPOSITORY, 103 + self::FIELD_REPOSITORY_PROJECTS, 98 104 self::FIELD_DIFF_FILE, 99 105 self::FIELD_DIFF_CONTENT, 100 106 self::FIELD_DIFF_ADDED_CONTENT, ··· 175 181 $object->commitData = $commit_data; 176 182 177 183 return $object; 184 + } 185 + 186 + public function setCommit(PhabricatorRepositoryCommit $commit) { 187 + $viewer = PhabricatorUser::getOmnipotentUser(); 188 + 189 + $repository = id(new PhabricatorRepositoryQuery()) 190 + ->setViewer($viewer) 191 + ->withIDs(array($commit->getRepositoryID())) 192 + ->needProjectPHIDs(true) 193 + ->executeOne(); 194 + if (!$repository) { 195 + throw new Exception(pht('Unable to load repository!')); 196 + } 197 + 198 + $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 199 + 'commitID = %d', 200 + $commit->getID()); 201 + if (!$data) { 202 + throw new Exception(pht('Unable to load commit data!')); 203 + } 204 + 205 + $this->commit = clone $commit; 206 + $this->commit->attachRepository($repository); 207 + $this->commit->attachCommitData($data); 208 + 209 + $this->repository = $repository; 210 + $this->commitData = $data; 211 + 212 + return $this; 178 213 } 179 214 180 215 public function getPHID() { ··· 375 410 return $this->loadAffectedPaths(); 376 411 case self::FIELD_REPOSITORY: 377 412 return $this->repository->getPHID(); 413 + case self::FIELD_REPOSITORY_PROJECTS: 414 + return $this->repository->getProjectPHIDs(); 378 415 case self::FIELD_DIFF_CONTENT: 379 416 return $this->getDiffContent('*'); 380 417 case self::FIELD_DIFF_ADDED_CONTENT:
+27 -16
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 64 64 self::FIELD_REVIEWERS, 65 65 self::FIELD_CC, 66 66 self::FIELD_REPOSITORY, 67 + self::FIELD_REPOSITORY_PROJECTS, 67 68 self::FIELD_DIFF_FILE, 68 69 self::FIELD_DIFF_CONTENT, 69 70 self::FIELD_DIFF_ADDED_CONTENT, ··· 152 153 if ($this->repository === null) { 153 154 $this->repository = false; 154 155 155 - // TODO: (T603) Implement policy stuff in Herald. 156 156 $viewer = PhabricatorUser::getOmnipotentUser(); 157 + $repository_phid = null; 157 158 158 159 $revision = $this->revision; 159 160 if ($revision->getRepositoryPHID()) { 160 - $repositories = id(new PhabricatorRepositoryQuery()) 161 + $repository_phid = $revision->getRepositoryPHID(); 162 + } else { 163 + $repository = id(new DifferentialRepositoryLookup()) 161 164 ->setViewer($viewer) 162 - ->withPHIDs(array($revision->getRepositoryPHID())) 163 - ->execute(); 164 - if ($repositories) { 165 - $this->repository = head($repositories); 166 - return $this->repository; 165 + ->setDiff($this->diff) 166 + ->lookupRepository(); 167 + if ($repository) { 168 + // We want to get the projects for this repository too, so run a 169 + // full query for it below. 170 + $repository_phid = $repository->getPHID(); 167 171 } 168 172 } 169 173 170 - $repository = id(new DifferentialRepositoryLookup()) 171 - ->setViewer($viewer) 172 - ->setDiff($this->diff) 173 - ->lookupRepository(); 174 - if ($repository) { 175 - $this->repository = $repository; 176 - return $this->repository; 174 + if ($repository_phid) { 175 + $repository = id(new PhabricatorRepositoryQuery()) 176 + ->setViewer($viewer) 177 + ->withPHIDs(array($repository_phid)) 178 + ->needProjectPHIDs(true) 179 + ->executeOne(); 180 + if ($repository) { 181 + $this->repository = $repository; 182 + } 177 183 } 178 - 179 - $repository = false; 180 184 } 185 + 181 186 return $this->repository; 182 187 } 183 188 ··· 345 350 return null; 346 351 } 347 352 return $repository->getPHID(); 353 + case self::FIELD_REPOSITORY_PROJECTS: 354 + $repository = $this->loadRepository(); 355 + if (!$repository) { 356 + return null; 357 + } 358 + return $repository->getProjectPHIDs(); 348 359 case self::FIELD_DIFF_CONTENT: 349 360 return $this->loadContentDictionary(); 350 361 case self::FIELD_DIFF_ADDED_CONTENT:
+2 -7
src/applications/herald/controller/HeraldTestConsoleController.php
··· 39 39 $object, 40 40 $object->loadActiveDiff()); 41 41 } else if ($object instanceof PhabricatorRepositoryCommit) { 42 - $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 43 - 'commitID = %d', 44 - $object->getID()); 45 - $adapter = HeraldCommitAdapter::newLegacyAdapter( 46 - $object->getRepository(), 47 - $object, 48 - $data); 42 + $adapter = id(new HeraldCommitAdapter()) 43 + ->setCommit($object); 49 44 } else if ($object instanceof ManiphestTask) { 50 45 $adapter = id(new HeraldManiphestTaskAdapter()) 51 46 ->setTask($object);
+1 -1
src/applications/herald/storage/HeraldRule.php
··· 17 17 protected $isDisabled = 0; 18 18 protected $triggerObjectPHID; 19 19 20 - protected $configVersion = 26; 20 + protected $configVersion = 27; 21 21 22 22 // phids for which this rule has been applied 23 23 private $ruleApplied = self::ATTACHABLE;
+2 -4
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 42 42 'or no longer exists.')); 43 43 } 44 44 45 - $adapter = HeraldCommitAdapter::newLegacyAdapter( 46 - $repository, 47 - $commit, 48 - $data); 45 + $adapter = id(new HeraldCommitAdapter()) 46 + ->setCommit($commit); 49 47 50 48 $rules = id(new HeraldRuleQuery()) 51 49 ->setViewer(PhabricatorUser::getOmnipotentUser())