1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 05:20:56 +01:00

Fix a Herald issue where testing commits against rules with revision-related conditions would fail

Summary:
Fixes T11610. Clean up some sketchy old code from long ago.

If you had rules that use conditions like "Accepted revision exists" and ran them in the test console, we'd never load the "CommitData" and fatal.

Instead, load CommitData in `newTestAdapter()` and generally make these pathways a little more modern.

Test Plan:
  - Wrote an "Accepted Revision Exists" rule.
  - Ran a commit in the test console.
  - Before patch, got fatal from T11610.
  - After patch, got clean test result.
  - Also pushed a commit and reviewed the transcript to make sure the rule ran properly.

Reviewers: joshuaspence, chad

Reviewed By: chad

Maniphest Tasks: T11610

Differential Revision: https://secure.phabricator.com/D16522
This commit is contained in:
epriestley 2016-09-08 16:08:49 -07:00
parent 17cd119b91
commit 8d048f06ab
5 changed files with 27 additions and 34 deletions

View file

@ -886,9 +886,8 @@ final class PhabricatorAuditEditor
protected function buildHeraldAdapter(
PhabricatorLiskDAO $object,
array $xactions) {
return id(new HeraldCommitAdapter())
->setCommit($object);
->setObject($object);
}
protected function didApplyHeraldRules(

View file

@ -29,7 +29,7 @@ final class HeraldDifferentialRevisionAdapter
'Test rules which run when a revision is created or updated.');
}
public function newTestAdapter($object) {
public function newTestAdapter(PhabricatorUser $viewer, $object) {
return self::newLegacyAdapter(
$object,
$object->loadActiveDiff());

View file

@ -8,7 +8,6 @@ final class HeraldCommitAdapter
protected $revision;
protected $commit;
protected $commitData;
private $commitDiff;
protected $affectedPaths;
@ -35,6 +34,23 @@ final class HeraldCommitAdapter
'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() {
$this->commit = $this->newObject();
}
@ -100,33 +116,6 @@ final class HeraldCommitAdapter
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() {
return $this->commit->getMonogram();
}
@ -171,7 +160,10 @@ final class HeraldCommitAdapter
public function loadDifferentialRevision() {
if ($this->affectedRevision === null) {
$this->affectedRevision = false;
$data = $this->commitData;
$commit = $this->getObject();
$data = $commit->getCommitData();
$revision_id = $data->getCommitDetail('differential.revisionID');
if ($revision_id) {
// NOTE: The Herald rule owner might not actually have access to

View file

@ -224,7 +224,7 @@ abstract class HeraldAdapter extends Phobject {
return $this->isTestAdapterForObject($object);
}
public function newTestAdapter($object) {
public function newTestAdapter(PhabricatorUser $viewer, $object) {
return id(clone $this)
->setObject($object);
}

View file

@ -142,7 +142,9 @@ final class HeraldTestConsoleController extends HeraldController {
if ($request->isFormPost() && $adapter_key) {
if (isset($can_select[$adapter_key])) {
$adapter = $can_select[$adapter_key]->newTestAdapter($object);
$adapter = $can_select[$adapter_key]->newTestAdapter(
$viewer,
$object);
$this->setTestAdapter($adapter);
return null;
}