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 $commit; | protected $commit; | ||||
protected $commitData; | |||||
private $commitDiff; | private $commitDiff; | ||||
protected $affectedPaths; | protected $affectedPaths; | ||||
protected $affectedRevision; | protected $affectedRevision; | ||||
protected $affectedPackages; | protected $affectedPackages; | ||||
protected $auditNeededPackages; | protected $auditNeededPackages; | ||||
private $buildRequests = array(); | private $buildRequests = array(); | ||||
Show All 10 Lines | public function isTestAdapterForObject($object) { | ||||
return ($object instanceof PhabricatorRepositoryCommit); | return ($object instanceof PhabricatorRepositoryCommit); | ||||
} | } | ||||
public function getAdapterTestDescription() { | public function getAdapterTestDescription() { | ||||
return pht( | return pht( | ||||
'Test rules which run after a commit is discovered and imported.'); | 'Test rules which run after a commit is discovered and imported.'); | ||||
} | } | ||||
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); | |||||
} | |||||
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; | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | return array_merge( | ||||
), | ), | ||||
$this->loadEdgePHIDs($project_type)); | $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 function setCommit(PhabricatorRepositoryCommit $commit) { | |||||
$viewer = PhabricatorUser::getOmnipotentUser(); | |||||
$repository = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($commit->getRepositoryID())) | |||||
->executeOne(); | |||||
if (!$repository) { | |||||
throw new Exception(pht('Unable to load repository!')); | |||||
} | |||||
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( | |||||
'commitID = %d', | |||||
$commit->getID()); | |||||
if (!$data) { | |||||
throw new Exception(pht('Unable to load commit data!')); | |||||
} | |||||
$this->commit = clone $commit; | |||||
$this->commit->attachRepository($repository); | |||||
$this->commit->attachCommitData($data); | |||||
$this->commitData = $data; | |||||
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->getRepository(), | $this->getRepository(), | ||||
Show All 28 Lines | if ($this->auditNeededPackages === null) { | ||||
$this->auditNeededPackages = $requests; | $this->auditNeededPackages = $requests; | ||||
} | } | ||||
return $this->auditNeededPackages; | return $this->auditNeededPackages; | ||||
} | } | ||||
public function loadDifferentialRevision() { | public function loadDifferentialRevision() { | ||||
if ($this->affectedRevision === null) { | if ($this->affectedRevision === null) { | ||||
$this->affectedRevision = false; | $this->affectedRevision = false; | ||||
$data = $this->commitData; | |||||
$commit = $this->getObject(); | |||||
$data = $commit->getCommitData(); | |||||
$revision_id = $data->getCommitDetail('differential.revisionID'); | $revision_id = $data->getCommitDetail('differential.revisionID'); | ||||
if ($revision_id) { | if ($revision_id) { | ||||
// NOTE: The Herald rule owner might not actually have access to | // NOTE: The Herald rule owner might not actually have access to | ||||
// the revision, and can control which revision a commit is | // the revision, and can control which revision a commit is | ||||
// associated with by putting text in the commit message. However, | // associated with by putting text in the commit message. However, | ||||
// the rules they can write against revisions don't actually expose | // the rules they can write against revisions don't actually expose | ||||
// anything interesting, so it seems reasonable to load unconditionally | // anything interesting, so it seems reasonable to load unconditionally | ||||
// here. | // here. | ||||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |