mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
Fix Herald test adapter for commits
Summary: Fixes T11488. I broke this in D16360, I think by doing a little extra refactoring after testing it. This code is very old, before commits always needed to have repositories attached in order to do policy checks. Modernize it by mostly just using the repository which is present on the Commit object, and using the existing edge cache. Test Plan: Ran a commit through the Herald test adapter. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11488 Differential Revision: https://secure.phabricator.com/D16413
This commit is contained in:
parent
f46cf99274
commit
f659b8743a
1 changed files with 12 additions and 24 deletions
|
@ -7,7 +7,6 @@ final class HeraldCommitAdapter
|
|||
protected $diff;
|
||||
protected $revision;
|
||||
|
||||
protected $repository;
|
||||
protected $commit;
|
||||
protected $commitData;
|
||||
private $commitDiff;
|
||||
|
@ -42,6 +41,7 @@ final class HeraldCommitAdapter
|
|||
|
||||
public function setObject($object) {
|
||||
$this->commit = $object;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -86,41 +86,26 @@ final class HeraldCommitAdapter
|
|||
}
|
||||
|
||||
public function getTriggerObjectPHIDs() {
|
||||
$project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
$this->repository->getPHID(),
|
||||
$this->getRepository()->getPHID(),
|
||||
$this->getPHID(),
|
||||
),
|
||||
$this->repository->getProjectPHIDs());
|
||||
$this->loadEdgePHIDs($project_type));
|
||||
}
|
||||
|
||||
public function explainValidTriggerObjects() {
|
||||
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) {
|
||||
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||
|
||||
$repository = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($commit->getRepositoryID()))
|
||||
->needProjectPHIDs(true)
|
||||
->executeOne();
|
||||
if (!$repository) {
|
||||
throw new Exception(pht('Unable to load repository!'));
|
||||
|
@ -137,7 +122,6 @@ final class HeraldCommitAdapter
|
|||
$this->commit->attachRepository($repository);
|
||||
$this->commit->attachCommitData($data);
|
||||
|
||||
$this->repository = $repository;
|
||||
$this->commitData = $data;
|
||||
|
||||
return $this;
|
||||
|
@ -150,7 +134,7 @@ final class HeraldCommitAdapter
|
|||
public function loadAffectedPaths() {
|
||||
if ($this->affectedPaths === null) {
|
||||
$result = PhabricatorOwnerPathQuery::loadAffectedPaths(
|
||||
$this->repository,
|
||||
$this->getRepository(),
|
||||
$this->commit,
|
||||
PhabricatorUser::getOmnipotentUser());
|
||||
$this->affectedPaths = $result;
|
||||
|
@ -161,7 +145,7 @@ final class HeraldCommitAdapter
|
|||
public function loadAffectedPackages() {
|
||||
if ($this->affectedPackages === null) {
|
||||
$packages = PhabricatorOwnersPackage::loadAffectedPackages(
|
||||
$this->repository,
|
||||
$this->getRepository(),
|
||||
$this->loadAffectedPaths());
|
||||
$this->affectedPackages = $packages;
|
||||
}
|
||||
|
@ -314,7 +298,7 @@ final class HeraldCommitAdapter
|
|||
$drequest = DiffusionRequest::newFromDictionary(
|
||||
array(
|
||||
'user' => $viewer,
|
||||
'repository' => $this->repository,
|
||||
'repository' => $this->getRepository(),
|
||||
'commit' => $this->commit->getCommitIdentifier(),
|
||||
));
|
||||
|
||||
|
@ -325,6 +309,10 @@ final class HeraldCommitAdapter
|
|||
$params);
|
||||
}
|
||||
|
||||
private function getRepository() {
|
||||
return $this->getObject()->getRepository();
|
||||
}
|
||||
|
||||
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue