1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

Support "Repository's projects" field in Commit and Differential Revision rules

Summary: This also cleans up some code a little bit. Most of the gymnastics are to make sure we call `needProjectPHIDs()` appropriately.

Test Plan: Created new commit and revision rules with this field. Ran commits and revisions through the test console. Field behavior seemed correct.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, dctrwatson

Differential Revision: https://secure.phabricator.com/D7923
This commit is contained in:
epriestley 2014-01-09 15:56:24 -08:00
parent c020837397
commit efe187d5be
5 changed files with 74 additions and 33 deletions

View file

@ -64,19 +64,24 @@ final class HeraldCommitAdapter extends HeraldAdapter {
if ($object instanceof PhabricatorRepository) {
return true;
}
if ($object instanceof PhabricatorProject) {
return true;
}
return false;
}
public function getTriggerObjectPHIDs() {
return array(
$this->repository->getPHID(),
$this->getPHID(),
);
return array_merge(
array(
$this->repository->getPHID(),
$this->getPHID(),
),
$this->repository->getProjectPHIDs());
}
public function explainValidTriggerObjects() {
return pht(
'This rule can trigger for **repositories**.');
'This rule can trigger for **repositories** and **projects**.');
}
public function getFieldNameMap() {
@ -95,6 +100,7 @@ final class HeraldCommitAdapter extends HeraldAdapter {
self::FIELD_COMMITTER,
self::FIELD_REVIEWER,
self::FIELD_REPOSITORY,
self::FIELD_REPOSITORY_PROJECTS,
self::FIELD_DIFF_FILE,
self::FIELD_DIFF_CONTENT,
self::FIELD_DIFF_ADDED_CONTENT,
@ -177,6 +183,35 @@ final class HeraldCommitAdapter extends HeraldAdapter {
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!'));
}
$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->repository = $repository;
$this->commitData = $data;
return $this;
}
public function getPHID() {
return $this->commit->getPHID();
}
@ -375,6 +410,8 @@ final class HeraldCommitAdapter extends HeraldAdapter {
return $this->loadAffectedPaths();
case self::FIELD_REPOSITORY:
return $this->repository->getPHID();
case self::FIELD_REPOSITORY_PROJECTS:
return $this->repository->getProjectPHIDs();
case self::FIELD_DIFF_CONTENT:
return $this->getDiffContent('*');
case self::FIELD_DIFF_ADDED_CONTENT:

View file

@ -64,6 +64,7 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
self::FIELD_REVIEWERS,
self::FIELD_CC,
self::FIELD_REPOSITORY,
self::FIELD_REPOSITORY_PROJECTS,
self::FIELD_DIFF_FILE,
self::FIELD_DIFF_CONTENT,
self::FIELD_DIFF_ADDED_CONTENT,
@ -152,32 +153,36 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
if ($this->repository === null) {
$this->repository = false;
// TODO: (T603) Implement policy stuff in Herald.
$viewer = PhabricatorUser::getOmnipotentUser();
$repository_phid = null;
$revision = $this->revision;
if ($revision->getRepositoryPHID()) {
$repositories = id(new PhabricatorRepositoryQuery())
$repository_phid = $revision->getRepositoryPHID();
} else {
$repository = id(new DifferentialRepositoryLookup())
->setViewer($viewer)
->withPHIDs(array($revision->getRepositoryPHID()))
->execute();
if ($repositories) {
$this->repository = head($repositories);
return $this->repository;
->setDiff($this->diff)
->lookupRepository();
if ($repository) {
// We want to get the projects for this repository too, so run a
// full query for it below.
$repository_phid = $repository->getPHID();
}
}
$repository = id(new DifferentialRepositoryLookup())
->setViewer($viewer)
->setDiff($this->diff)
->lookupRepository();
if ($repository) {
$this->repository = $repository;
return $this->repository;
if ($repository_phid) {
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withPHIDs(array($repository_phid))
->needProjectPHIDs(true)
->executeOne();
if ($repository) {
$this->repository = $repository;
}
}
$repository = false;
}
return $this->repository;
}
@ -345,6 +350,12 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
return null;
}
return $repository->getPHID();
case self::FIELD_REPOSITORY_PROJECTS:
$repository = $this->loadRepository();
if (!$repository) {
return null;
}
return $repository->getProjectPHIDs();
case self::FIELD_DIFF_CONTENT:
return $this->loadContentDictionary();
case self::FIELD_DIFF_ADDED_CONTENT:

View file

@ -39,13 +39,8 @@ final class HeraldTestConsoleController extends HeraldController {
$object,
$object->loadActiveDiff());
} else if ($object instanceof PhabricatorRepositoryCommit) {
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d',
$object->getID());
$adapter = HeraldCommitAdapter::newLegacyAdapter(
$object->getRepository(),
$object,
$data);
$adapter = id(new HeraldCommitAdapter())
->setCommit($object);
} else if ($object instanceof ManiphestTask) {
$adapter = id(new HeraldManiphestTaskAdapter())
->setTask($object);

View file

@ -17,7 +17,7 @@ final class HeraldRule extends HeraldDAO
protected $isDisabled = 0;
protected $triggerObjectPHID;
protected $configVersion = 26;
protected $configVersion = 27;
// phids for which this rule has been applied
private $ruleApplied = self::ATTACHABLE;

View file

@ -42,10 +42,8 @@ final class PhabricatorRepositoryCommitHeraldWorker
'or no longer exists.'));
}
$adapter = HeraldCommitAdapter::newLegacyAdapter(
$repository,
$commit,
$data);
$adapter = id(new HeraldCommitAdapter())
->setCommit($commit);
$rules = id(new HeraldRuleQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())