Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/herald/HeraldCommitAdapter.php
<?php | <?php | ||||
final class HeraldCommitAdapter | final class HeraldCommitAdapter | ||||
extends HeraldAdapter | extends HeraldAdapter | ||||
implements HarbormasterBuildableAdapterInterface { | implements HarbormasterBuildableAdapterInterface { | ||||
protected $diff; | protected $diff; | ||||
protected $revision; | protected $revision; | ||||
protected $repository; | |||||
protected $commit; | protected $commit; | ||||
protected $commitData; | protected $commitData; | ||||
private $commitDiff; | private $commitDiff; | ||||
protected $affectedPaths; | protected $affectedPaths; | ||||
protected $affectedRevision; | protected $affectedRevision; | ||||
protected $affectedPackages; | protected $affectedPackages; | ||||
protected $auditNeededPackages; | protected $auditNeededPackages; | ||||
Show All 18 Lines | final class HeraldCommitAdapter | ||||
} | } | ||||
protected function initializeNewAdapter() { | protected function initializeNewAdapter() { | ||||
$this->commit = $this->newObject(); | $this->commit = $this->newObject(); | ||||
} | } | ||||
public function setObject($object) { | public function setObject($object) { | ||||
$this->commit = $object; | $this->commit = $object; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getObject() { | public function getObject() { | ||||
return $this->commit; | return $this->commit; | ||||
} | } | ||||
public function getAdapterContentType() { | public function getAdapterContentType() { | ||||
Show All 28 Lines | public function canTriggerOnObject($object) { | ||||
} | } | ||||
if ($object instanceof PhabricatorProject) { | if ($object instanceof PhabricatorProject) { | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public function getTriggerObjectPHIDs() { | public function getTriggerObjectPHIDs() { | ||||
$project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; | |||||
return array_merge( | return array_merge( | ||||
array( | array( | ||||
$this->repository->getPHID(), | $this->getRepository()->getPHID(), | ||||
$this->getPHID(), | $this->getPHID(), | ||||
), | ), | ||||
$this->repository->getProjectPHIDs()); | $this->loadEdgePHIDs($project_type)); | ||||
} | } | ||||
public function explainValidTriggerObjects() { | public function explainValidTriggerObjects() { | ||||
return pht('This rule can trigger for **repositories** and **projects**.'); | 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) { | public function setCommit(PhabricatorRepositoryCommit $commit) { | ||||
$viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
$repository = id(new PhabricatorRepositoryQuery()) | $repository = id(new PhabricatorRepositoryQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($commit->getRepositoryID())) | ->withIDs(array($commit->getRepositoryID())) | ||||
->needProjectPHIDs(true) | |||||
->executeOne(); | ->executeOne(); | ||||
if (!$repository) { | if (!$repository) { | ||||
throw new Exception(pht('Unable to load repository!')); | throw new Exception(pht('Unable to load repository!')); | ||||
} | } | ||||
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( | $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( | ||||
'commitID = %d', | 'commitID = %d', | ||||
$commit->getID()); | $commit->getID()); | ||||
if (!$data) { | if (!$data) { | ||||
throw new Exception(pht('Unable to load commit data!')); | throw new Exception(pht('Unable to load commit data!')); | ||||
} | } | ||||
$this->commit = clone $commit; | $this->commit = clone $commit; | ||||
$this->commit->attachRepository($repository); | $this->commit->attachRepository($repository); | ||||
$this->commit->attachCommitData($data); | $this->commit->attachCommitData($data); | ||||
$this->repository = $repository; | |||||
$this->commitData = $data; | $this->commitData = $data; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getHeraldName() { | public function getHeraldName() { | ||||
return $this->commit->getMonogram(); | return $this->commit->getMonogram(); | ||||
} | } | ||||
public function loadAffectedPaths() { | public function loadAffectedPaths() { | ||||
if ($this->affectedPaths === null) { | if ($this->affectedPaths === null) { | ||||
$result = PhabricatorOwnerPathQuery::loadAffectedPaths( | $result = PhabricatorOwnerPathQuery::loadAffectedPaths( | ||||
$this->repository, | $this->getRepository(), | ||||
$this->commit, | $this->commit, | ||||
PhabricatorUser::getOmnipotentUser()); | PhabricatorUser::getOmnipotentUser()); | ||||
$this->affectedPaths = $result; | $this->affectedPaths = $result; | ||||
} | } | ||||
return $this->affectedPaths; | return $this->affectedPaths; | ||||
} | } | ||||
public function loadAffectedPackages() { | public function loadAffectedPackages() { | ||||
if ($this->affectedPackages === null) { | if ($this->affectedPackages === null) { | ||||
$packages = PhabricatorOwnersPackage::loadAffectedPackages( | $packages = PhabricatorOwnersPackage::loadAffectedPackages( | ||||
$this->repository, | $this->getRepository(), | ||||
$this->loadAffectedPaths()); | $this->loadAffectedPaths()); | ||||
$this->affectedPackages = $packages; | $this->affectedPackages = $packages; | ||||
} | } | ||||
return $this->affectedPackages; | return $this->affectedPackages; | ||||
} | } | ||||
public function loadAuditNeededPackages() { | public function loadAuditNeededPackages() { | ||||
if ($this->auditNeededPackages === null) { | if ($this->auditNeededPackages === null) { | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | final class HeraldCommitAdapter | ||||
} | } | ||||
private function callConduit($method, array $params) { | private function callConduit($method, array $params) { | ||||
$viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
$drequest = DiffusionRequest::newFromDictionary( | $drequest = DiffusionRequest::newFromDictionary( | ||||
array( | array( | ||||
'user' => $viewer, | 'user' => $viewer, | ||||
'repository' => $this->repository, | 'repository' => $this->getRepository(), | ||||
'commit' => $this->commit->getCommitIdentifier(), | 'commit' => $this->commit->getCommitIdentifier(), | ||||
)); | )); | ||||
return DiffusionQuery::callConduitWithDiffusionRequest( | return DiffusionQuery::callConduitWithDiffusionRequest( | ||||
$viewer, | $viewer, | ||||
$drequest, | $drequest, | ||||
$method, | $method, | ||||
$params); | $params); | ||||
} | } | ||||
private function getRepository() { | |||||
return $this->getObject()->getRepository(); | |||||
} | |||||
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */ | /* -( HarbormasterBuildableAdapterInterface )------------------------------ */ | ||||
public function getHarbormasterBuildablePHID() { | public function getHarbormasterBuildablePHID() { | ||||
return $this->getObject()->getPHID(); | return $this->getObject()->getPHID(); | ||||
} | } | ||||
public function getHarbormasterContainerPHID() { | public function getHarbormasterContainerPHID() { | ||||
Show All 13 Lines |