mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
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
This commit is contained in:
parent
41f143f7fe
commit
6628cd2b4f
5 changed files with 39 additions and 19 deletions
|
@ -10,7 +10,7 @@ final class DiffusionCommitAuthorHeraldField
|
|||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $object->getCommitData()->getCommitDetail('authorPHID');
|
||||
return $this->getAdapter()->getAuthorPHID();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardType() {
|
||||
|
|
|
@ -11,14 +11,13 @@ final class DiffusionCommitAuthorProjectsHeraldField
|
|||
|
||||
public function getHeraldFieldValue($object) {
|
||||
$adapter = $this->getAdapter();
|
||||
$viewer = $adapter->getViewer();
|
||||
|
||||
$phid = $object->getCommitData()->getCommitDetail('authorPHID');
|
||||
$phid = $adapter->getAuthorPHID();
|
||||
if (!$phid) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$viewer = $adapter->getViewer();
|
||||
|
||||
$projects = id(new PhabricatorProjectQuery())
|
||||
->setViewer($viewer)
|
||||
->withMemberPHIDs(array($phid))
|
||||
|
|
|
@ -10,7 +10,7 @@ final class DiffusionCommitCommitterHeraldField
|
|||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $object->getCommitData()->getCommitDetail('committerPHID');
|
||||
return $this->getAdapter()->getCommitterPHID();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardType() {
|
||||
|
|
|
@ -11,8 +11,9 @@ final class DiffusionCommitCommitterProjectsHeraldField
|
|||
|
||||
public function getHeraldFieldValue($object) {
|
||||
$adapter = $this->getAdapter();
|
||||
$viewer = $adapter->getViewer();
|
||||
|
||||
$phid = $object->getCommitData()->getCommitDetail('committerPHID');
|
||||
$phid = $adapter->getCommitterPHID();
|
||||
if (!$phid) {
|
||||
return array();
|
||||
}
|
||||
|
|
|
@ -35,18 +35,6 @@ final class HeraldCommitAdapter
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -56,7 +44,23 @@ final class HeraldCommitAdapter
|
|||
}
|
||||
|
||||
public function setObject($object) {
|
||||
$this->commit = $object;
|
||||
$viewer = $this->getViewer();
|
||||
$commit_phid = $object->getPHID();
|
||||
|
||||
$commit = id(new DiffusionCommitQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($commit_phid))
|
||||
->needCommitData(true)
|
||||
->needIdentities(true)
|
||||
->executeOne();
|
||||
if (!$commit) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Failed to reload commit ("%s") to fetch commit data.',
|
||||
$commit_phid));
|
||||
}
|
||||
|
||||
$this->commit = $commit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -352,6 +356,22 @@ final class HeraldCommitAdapter
|
|||
return $this->getObject()->getRepository();
|
||||
}
|
||||
|
||||
public function getAuthorPHID() {
|
||||
return $this->getObject()->getEffectiveAuthorPHID();
|
||||
}
|
||||
|
||||
public function getCommitterPHID() {
|
||||
$commit = $this->getObject();
|
||||
|
||||
if ($commit->hasCommitterIdentity()) {
|
||||
$identity = $commit->getCommitterIdentity();
|
||||
return $identity->getCurrentEffectiveUserPHID();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue