@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

In Herald "Commit" rules, use repository identities to identify authors and committers

Summary: Ref T13480. The Herald "Commit" rules still use raw commit data properties to identify authors and committers. Instead, use repository identities.

Test Plan: Wrote a Herald rule using all four fields, ran it against various commits with and without known authors. Checked transcript for sensible field values.

Maniphest Tasks: T13480

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

+39 -19
+1 -1
src/applications/diffusion/herald/DiffusionCommitAuthorHeraldField.php
··· 10 10 } 11 11 12 12 public function getHeraldFieldValue($object) { 13 - return $object->getCommitData()->getCommitDetail('authorPHID'); 13 + return $this->getAdapter()->getAuthorPHID(); 14 14 } 15 15 16 16 protected function getHeraldFieldStandardType() {
+2 -3
src/applications/diffusion/herald/DiffusionCommitAuthorProjectsHeraldField.php
··· 11 11 12 12 public function getHeraldFieldValue($object) { 13 13 $adapter = $this->getAdapter(); 14 + $viewer = $adapter->getViewer(); 14 15 15 - $phid = $object->getCommitData()->getCommitDetail('authorPHID'); 16 + $phid = $adapter->getAuthorPHID(); 16 17 if (!$phid) { 17 18 return array(); 18 19 } 19 - 20 - $viewer = $adapter->getViewer(); 21 20 22 21 $projects = id(new PhabricatorProjectQuery()) 23 22 ->setViewer($viewer)
+1 -1
src/applications/diffusion/herald/DiffusionCommitCommitterHeraldField.php
··· 10 10 } 11 11 12 12 public function getHeraldFieldValue($object) { 13 - return $object->getCommitData()->getCommitDetail('committerPHID'); 13 + return $this->getAdapter()->getCommitterPHID(); 14 14 } 15 15 16 16 protected function getHeraldFieldStandardType() {
+2 -1
src/applications/diffusion/herald/DiffusionCommitCommitterProjectsHeraldField.php
··· 11 11 12 12 public function getHeraldFieldValue($object) { 13 13 $adapter = $this->getAdapter(); 14 + $viewer = $adapter->getViewer(); 14 15 15 - $phid = $object->getCommitData()->getCommitDetail('committerPHID'); 16 + $phid = $adapter->getCommitterPHID(); 16 17 if (!$phid) { 17 18 return array(); 18 19 }
+33 -13
src/applications/diffusion/herald/HeraldCommitAdapter.php
··· 35 35 } 36 36 37 37 public function newTestAdapter(PhabricatorUser $viewer, $object) { 38 - $object = id(new DiffusionCommitQuery()) 39 - ->setViewer($viewer) 40 - ->withPHIDs(array($object->getPHID())) 41 - ->needCommitData(true) 42 - ->executeOne(); 43 - if (!$object) { 44 - throw new Exception( 45 - pht( 46 - 'Failed to reload commit ("%s") to fetch commit data.', 47 - $object->getPHID())); 48 - } 49 - 50 38 return id(clone $this) 51 39 ->setObject($object); 52 40 } ··· 56 44 } 57 45 58 46 public function setObject($object) { 59 - $this->commit = $object; 47 + $viewer = $this->getViewer(); 48 + $commit_phid = $object->getPHID(); 49 + 50 + $commit = id(new DiffusionCommitQuery()) 51 + ->setViewer($viewer) 52 + ->withPHIDs(array($commit_phid)) 53 + ->needCommitData(true) 54 + ->needIdentities(true) 55 + ->executeOne(); 56 + if (!$commit) { 57 + throw new Exception( 58 + pht( 59 + 'Failed to reload commit ("%s") to fetch commit data.', 60 + $commit_phid)); 61 + } 62 + 63 + $this->commit = $commit; 60 64 61 65 return $this; 62 66 } ··· 351 355 private function getRepository() { 352 356 return $this->getObject()->getRepository(); 353 357 } 358 + 359 + public function getAuthorPHID() { 360 + return $this->getObject()->getEffectiveAuthorPHID(); 361 + } 362 + 363 + public function getCommitterPHID() { 364 + $commit = $this->getObject(); 365 + 366 + if ($commit->hasCommitterIdentity()) { 367 + $identity = $commit->getCommitterIdentity(); 368 + return $identity->getCurrentEffectiveUserPHID(); 369 + } 370 + 371 + return null; 372 + } 373 + 354 374 355 375 /* -( HarbormasterBuildableAdapterInterface )------------------------------ */ 356 376