1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +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', 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php',
'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php', 'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php',
'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php', 'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php',
'HeraldDryRunAdapter' => 'applications/herald/adapter/HeraldDryRunAdapter.php',
'HeraldEditLogQuery' => 'applications/herald/query/HeraldEditLogQuery.php', 'HeraldEditLogQuery' => 'applications/herald/query/HeraldEditLogQuery.php',
'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php', 'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php',
'HeraldEngine' => 'applications/herald/engine/HeraldEngine.php', 'HeraldEngine' => 'applications/herald/engine/HeraldEngine.php',
@ -2615,7 +2614,6 @@ phutil_register_library_map(array(
'HeraldDAO' => 'PhabricatorLiskDAO', 'HeraldDAO' => 'PhabricatorLiskDAO',
'HeraldDeleteController' => 'HeraldController', 'HeraldDeleteController' => 'HeraldController',
'HeraldDifferentialRevisionAdapter' => 'HeraldAdapter', 'HeraldDifferentialRevisionAdapter' => 'HeraldAdapter',
'HeraldDryRunAdapter' => 'HeraldAdapter',
'HeraldEditLogQuery' => 'PhabricatorOffsetPagedQuery', 'HeraldEditLogQuery' => 'PhabricatorOffsetPagedQuery',
'HeraldInvalidActionException' => 'Exception', 'HeraldInvalidActionException' => 'Exception',
'HeraldInvalidConditionException' => '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) ->needValidateAuthors(true)
->execute(); ->execute();
$engine = new HeraldEngine(); $engine = id(new HeraldEngine())
$effects = $engine->applyRules($rules, $adapter); ->setDryRun(true);
$dry_run = new HeraldDryRunAdapter(); $effects = $engine->applyRules($rules, $adapter);
$engine->applyEffects($effects, $dry_run, $rules); $engine->applyEffects($effects, $adapter, $rules);
$xscript = $engine->getTranscript(); $xscript = $engine->getTranscript();

View file

@ -9,6 +9,16 @@ final class HeraldEngine {
protected $fieldCache = array(); protected $fieldCache = array();
protected $object = null; 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) { public function getRule($id) {
return idx($this->rules, $id); return idx($this->rules, $id);
@ -111,24 +121,34 @@ final class HeraldEngine {
public function applyEffects( public function applyEffects(
array $effects, array $effects,
HeraldAdapter $object, HeraldAdapter $adapter,
array $rules) { array $rules) {
assert_instances_of($effects, 'HeraldEffect'); assert_instances_of($effects, 'HeraldEffect');
assert_instances_of($rules, 'HeraldRule'); assert_instances_of($rules, 'HeraldRule');
$this->transcript->setDryRun((int)($object instanceof HeraldDryRunAdapter)); $this->transcript->setDryRun((int)$this->getDryRun());
$xscripts = $object->applyHeraldEffects($effects); if ($this->getDryRun()) {
foreach ($xscripts as $apply_xscript) { $xscripts = array();
if (!($apply_xscript instanceof HeraldApplyTranscript)) { foreach ($effects as $effect) {
throw new Exception( $xscripts[] = new HeraldApplyTranscript(
"Heraldable must return HeraldApplyTranscripts from ". $effect,
"applyHeraldEffect()."); 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); $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'); $rules = mpull($rules, null, 'getID');
$applied_ids = array(); $applied_ids = array();
@ -163,7 +183,7 @@ final class HeraldEngine {
$sql[] = qsprintf( $sql[] = qsprintf(
$conn_w, $conn_w,
'(%s, %d)', '(%s, %d)',
$object->getPHID(), $adapter->getPHID(),
$id); $id);
} }
queryfx( queryfx(
@ -173,7 +193,6 @@ final class HeraldEngine {
implode(', ', $sql)); implode(', ', $sql));
} }
} }
}
public function getTranscript() { public function getTranscript() {
$this->transcript->save(); $this->transcript->save();

View file

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