mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +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 $diff;
|
||||||
protected $revision;
|
protected $revision;
|
||||||
|
|
||||||
protected $repository;
|
|
||||||
protected $commit;
|
protected $commit;
|
||||||
protected $commitData;
|
protected $commitData;
|
||||||
private $commitDiff;
|
private $commitDiff;
|
||||||
|
@ -42,6 +41,7 @@ final class HeraldCommitAdapter
|
||||||
|
|
||||||
public function setObject($object) {
|
public function setObject($object) {
|
||||||
$this->commit = $object;
|
$this->commit = $object;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,41 +86,26 @@ final class HeraldCommitAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
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!'));
|
||||||
|
@ -137,7 +122,6 @@ final class HeraldCommitAdapter
|
||||||
$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;
|
||||||
|
@ -150,7 +134,7 @@ final class HeraldCommitAdapter
|
||||||
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;
|
||||||
|
@ -161,7 +145,7 @@ final class HeraldCommitAdapter
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +298,7 @@ final class HeraldCommitAdapter
|
||||||
$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(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -325,6 +309,10 @@ final class HeraldCommitAdapter
|
||||||
$params);
|
$params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getRepository() {
|
||||||
|
return $this->getObject()->getRepository();
|
||||||
|
}
|
||||||
|
|
||||||
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
|
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue