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

Remove HeraldDryRunAdapter

Summary: Ref T2769. This isn't a real adapter and its methods are increasingly hacky messes. Make "dry run" a first-class concept on the HeraldEngine instead and remove the adapter.

Test Plan: Ran Herald via test console and via CLI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

Differential Revision: https://secure.phabricator.com/D6693
This commit is contained in:
epriestley 2013-08-07 06:47:55 -07:00
parent ce163536ca
commit 4f49ec1cff
5 changed files with 69 additions and 97 deletions

View file

@ -604,7 +604,6 @@ phutil_register_library_map(array(
'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php',
'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php',
'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php',
'HeraldDryRunAdapter' => 'applications/herald/adapter/HeraldDryRunAdapter.php',
'HeraldEditLogQuery' => 'applications/herald/query/HeraldEditLogQuery.php',
'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php',
'HeraldEngine' => 'applications/herald/engine/HeraldEngine.php',
@ -2615,7 +2614,6 @@ phutil_register_library_map(array(
'HeraldDAO' => 'PhabricatorLiskDAO',
'HeraldDeleteController' => 'HeraldController',
'HeraldDifferentialRevisionAdapter' => 'HeraldAdapter',
'HeraldDryRunAdapter' => 'HeraldAdapter',
'HeraldEditLogQuery' => 'PhabricatorOffsetPagedQuery',
'HeraldInvalidActionException' => 'Exception',
'HeraldInvalidConditionException' => 'Exception',

View file

@ -1,44 +0,0 @@
<?php
final class HeraldDryRunAdapter extends HeraldAdapter {
public function getPHID() {
return 0;
}
public function isEnabled() {
return false;
}
public function getAdapterContentName() {
return null;
}
public function getHeraldName() {
return 'Dry Run';
}
public function getHeraldField($field) {
return null;
}
public function getFields() {
return array();
}
public function getActions($rule_type) {
return array();
}
public function applyHeraldEffects(array $effects) {
assert_instances_of($effects, 'HeraldEffect');
$results = array();
foreach ($effects as $effect) {
$results[] = new HeraldApplyTranscript(
$effect,
false,
pht('This was a dry run, so no actions were actually taken.'));
}
return $results;
}
}

View file

@ -76,11 +76,11 @@ final class HeraldTestConsoleController extends HeraldController {
->needValidateAuthors(true)
->execute();
$engine = new HeraldEngine();
$effects = $engine->applyRules($rules, $adapter);
$engine = id(new HeraldEngine())
->setDryRun(true);
$dry_run = new HeraldDryRunAdapter();
$engine->applyEffects($effects, $dry_run, $rules);
$effects = $engine->applyRules($rules, $adapter);
$engine->applyEffects($effects, $adapter, $rules);
$xscript = $engine->getTranscript();

View file

@ -9,6 +9,16 @@ final class HeraldEngine {
protected $fieldCache = array();
protected $object = null;
private $dryRun;
public function setDryRun($dry_run) {
$this->dryRun = $dry_run;
return $this;
}
public function getDryRun() {
return $this->dryRun;
}
public function getRule($id) {
return idx($this->rules, $id);
@ -111,24 +121,34 @@ final class HeraldEngine {
public function applyEffects(
array $effects,
HeraldAdapter $object,
HeraldAdapter $adapter,
array $rules) {
assert_instances_of($effects, 'HeraldEffect');
assert_instances_of($rules, 'HeraldRule');
$this->transcript->setDryRun((int)($object instanceof HeraldDryRunAdapter));
$this->transcript->setDryRun((int)$this->getDryRun());
$xscripts = $object->applyHeraldEffects($effects);
foreach ($xscripts as $apply_xscript) {
if (!($apply_xscript instanceof HeraldApplyTranscript)) {
throw new Exception(
"Heraldable must return HeraldApplyTranscripts from ".
"applyHeraldEffect().");
if ($this->getDryRun()) {
$xscripts = array();
foreach ($effects as $effect) {
$xscripts[] = new HeraldApplyTranscript(
$effect,
false,
pht('This was a dry run, so no actions were actually taken.'));
}
} else {
$xscripts = $adapter->applyHeraldEffects($effects);
}
assert_instances_of($xscripts, 'HeraldApplyTranscript');
foreach ($xscripts as $apply_xscript) {
$this->transcript->addApplyTranscript($apply_xscript);
}
if (!$this->transcript->getDryRun()) {
// For dry runs, don't mark the rule as having applied to the object.
if ($this->getDryRun()) {
return;
}
$rules = mpull($rules, null, 'getID');
$applied_ids = array();
@ -163,7 +183,7 @@ final class HeraldEngine {
$sql[] = qsprintf(
$conn_w,
'(%s, %d)',
$object->getPHID(),
$adapter->getPHID(),
$id);
}
queryfx(
@ -173,7 +193,6 @@ final class HeraldEngine {
implode(', ', $sql));
}
}
}
public function getTranscript() {
$this->transcript->save();

View file

@ -38,6 +38,7 @@ final class PhabricatorRepositoryCommitHeraldWorker
$effects = $engine->applyRules($rules, $adapter);
$engine->applyEffects($effects, $adapter, $rules);
$xscript = $engine->getTranscript();
$audit_phids = $adapter->getAuditMap();
if ($audit_phids) {
@ -63,8 +64,6 @@ final class PhabricatorRepositoryCommitHeraldWorker
return;
}
$xscript = $engine->getTranscript();
$revision = $adapter->loadDifferentialRevision();
if ($revision) {
$name = $revision->getTitle();