1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Very rough cut at Herald test console.

This commit is contained in:
epriestley 2011-03-24 13:49:21 -07:00
parent 6c31ce4980
commit 0b68b0f5bc
10 changed files with 198 additions and 17 deletions

View file

@ -178,7 +178,6 @@ phutil_register_library_map(array(
'DiffusionSvnFileContentQuery' => 'applications/diffusion/query/filecontent/svn',
'DiffusionSvnHistoryQuery' => 'applications/diffusion/query/history/svn',
'DiffusionView' => 'applications/diffusion/view/base',
'DryRunHeraldable' => 'applications/herald/heraldable/dryrun',
'HeraldAction' => 'applications/herald/storage/action',
'HeraldActionConfig' => 'applications/herald/config/action',
'HeraldApplyTranscript' => 'applications/herald/storage/transcript/apply',
@ -189,6 +188,7 @@ phutil_register_library_map(array(
'HeraldController' => 'applications/herald/controller/base',
'HeraldDAO' => 'applications/herald/storage/base',
'HeraldDeleteController' => 'applications/herald/controller/delete',
'HeraldDryRunAdapter' => 'applications/herald/adapter/dryrun',
'HeraldEffect' => 'applications/herald/engine/effect',
'HeraldEngine' => 'applications/herald/engine/engine',
'HeraldFieldConfig' => 'applications/herald/config/field',
@ -196,14 +196,15 @@ phutil_register_library_map(array(
'HeraldInvalidConditionException' => 'applications/herald/engine/engine/exception',
'HeraldInvalidFieldException' => 'applications/herald/engine/engine/exception',
'HeraldNewController' => 'applications/herald/controller/new',
'HeraldObjectAdapter' => 'applications/herald/adapter/base',
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/object',
'HeraldRecursiveConditionsException' => 'applications/herald/engine/engine/exception',
'HeraldRule' => 'applications/herald/storage/rule',
'HeraldRuleController' => 'applications/herald/controller/rule',
'HeraldRuleTranscript' => 'applications/herald/storage/transcript/rule',
'HeraldTestConsoleController' => 'applications/herald/controller/test',
'HeraldTranscript' => 'applications/herald/storage/transcript/base',
'HeraldValueTypeConfig' => 'applications/herald/config/valuetype',
'IHeraldable' => 'applications/herald/heraldable/base',
'Javelin' => 'infrastructure/javelin/api',
'LiskDAO' => 'storage/lisk/dao',
'ManiphestController' => 'applications/maniphest/controller/base',
@ -538,10 +539,12 @@ phutil_register_library_map(array(
'HeraldController' => 'PhabricatorController',
'HeraldDAO' => 'PhabricatorLiskDAO',
'HeraldDeleteController' => 'HeraldController',
'HeraldDryRunAdapter' => 'HeraldObjectAdapter',
'HeraldHomeController' => 'HeraldController',
'HeraldNewController' => 'HeraldController',
'HeraldRule' => 'HeraldDAO',
'HeraldRuleController' => 'HeraldController',
'HeraldTestConsoleController' => 'HeraldController',
'HeraldTranscript' => 'HeraldDAO',
'ManiphestController' => 'PhabricatorController',
'ManiphestDAO' => 'PhabricatorLiskDAO',
@ -702,9 +705,5 @@ phutil_register_library_map(array(
),
'requires_interface' =>
array(
'DryRunHeraldable' =>
array(
0 => 'IHeraldable',
),
),
));

View file

@ -223,6 +223,9 @@ class AphrontDefaultApplicationConfiguration
'new/(?:(?P<type>[^/]+)/)?$' => 'HeraldNewController',
'rule/(?:(?<id>\d+)/)?$' => 'HeraldRuleController',
'delete/(?P<id>\d+)/$' => 'HeraldDeleteController',
'test/$' => 'HeraldTestConsoleController',
'transcript/$' => 'HeraldTranscriptListController',
'transcript/(?P<id>\d+)/$' => 'HeraldTranscriptController',
),
);

View file

@ -16,13 +16,13 @@
* limitations under the License.
*/
interface IHeraldable {
abstract class HeraldObjectAdapter {
public function getFBID();
public function getHeraldName();
public function getHeraldTypeName();
public function getHeraldField($field_name);
public function applyHeraldEffects(array $effects);
abstract public function getPHID();
abstract public function getHeraldName();
abstract public function getHeraldTypeName();
abstract public function getHeraldField($field_name);
abstract public function applyHeraldEffects(array $effects);
}

View file

@ -7,4 +7,4 @@
phutil_require_source('IHeraldable.php');
phutil_require_source('HeraldObjectAdapter.php');

View file

@ -16,9 +16,9 @@
* limitations under the License.
*/
class DryRunHeraldable implements IHeraldable {
class HeraldDryRunAdapter extends HeraldObjectAdapter {
public function getFBID() {
public function getPHID() {
return 0;
}

View file

@ -6,8 +6,8 @@
phutil_require_module('phabricator', 'applications/herald/heraldable/base');
phutil_require_module('phabricator', 'applications/herald/adapter/base');
phutil_require_module('phabricator', 'applications/herald/storage/transcript/apply');
phutil_require_source('DryRunHeraldable.php');
phutil_require_source('HeraldDryRunAdapter.php');

View file

@ -27,6 +27,23 @@ abstract class HeraldController extends PhabricatorController {
$page->setGlyph("\xE2\x98\xBF");
$page->appendChild($view);
$page->setTabs(
array(
'rules' => array(
'href' => '/herald/',
'name' => 'Rules',
),
'test' => array(
'href' => '/herald/test/',
'name' => 'Test Console',
),
'transcripts' => array(
'href' => '/herald/transcript/',
'name' => 'Transcripts',
),
),
idx($data, 'tab'));
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());

View file

@ -123,6 +123,7 @@ class HeraldHomeController extends HeraldController {
$sidenav,
array(
'title' => 'Herald',
'tab' => 'rules',
));
}

View file

@ -0,0 +1,136 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class HeraldTestConsoleController extends HeraldController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$request = $this->getRequest();
$object_name = trim($request->getStr('object_name'));
$e_name = true;
$errors = array();
if ($request->isFormPost()) {
if (!$object_name) {
$e_name = 'Required';
$errors[] = 'An object name is required.';
}
if (!$errors) {
$matches = null;
$object = null;
if (preg_match('/^D(\d+)$/', $object_name, $matches)) {
$object = id(new DifferentialRevision())->load($matches[1]);
if (!$object) {
$e_name = 'Invalid';
$errors[] = 'No Differential Revision with that ID exists.';
}
} else if (preg_match('/^r([A-Z]+)(\w+)$/', $object_name, $matches)) {
$repo = id(new PhabricatorRepository())->loadOneWhere(
'callsign = %s',
$matches[1]);
if (!$repo) {
$e_name = 'Invalid';
$errors[] = 'There is no repository with the callsign '.
$matches[1].'.';
}
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
'repositoryID = %d AND commitIdentifier = %s',
$repo->getID(),
$matches[2]);
if (!$commit) {
$e_name = 'Invalid';
$errors[] = 'There is no commit with that identifier.';
}
} else {
$e_name = 'Invalid';
$errors[] = 'This object name is not recognized.';
}
if (!$errors) {
if ($object instanceof DifferentialRevision) {
$adapter = new HeraldDifferentialRevisionAdapter($object);
} else if ($object instanceof PhabricatorRepositoryCommit) {
$adapter = new HeraldDiffusionCommitAdapter($object);
} else {
throw new Exception("Can not build adapter for object!");
}
$rules = HeraldRule::loadAllByContentTypeWithFullData(
$adapter->getHeraldTypeName());
$engine = new HeraldEngine();
$effects = $engine->applyRules($rules, $adapter);
$dry_run = new HeraldDryRunAdapter();
$engine->applyEffects($effects, $dry_run);
$xscript = $engine->getTranscript();
return id(new AphrontRedirectResponse())
->setURI('/herald/transcript/'.$xscript->getID().'/');
}
}
}
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle('Form Errors');
$error_view->setErrors($errors);
} else {
$error_view = null;
}
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(
'<p class="aphront-form-instructions">Enter an object to test rules '.
'for, like a Diffusion commit (e.g., <tt>rX123</tt>) or a '.
'Differential revision (e.g., <tt>D123</tt>). You will be shown the '.
'results of a dry run on the object.</p>')
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Object Name')
->setName('object_name')
->setError($e_name)
->setValue($object_name))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Test Rules'));
$panel = new AphrontPanelView();
$panel->setHeader('Test Herald Rules');
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->appendChild($form);
return $this->buildStandardPageResponse(
array(
$error_view,
$panel,
),
array(
'title' => 'Test Console',
'tab' => 'test',
));
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'applications/herald/adapter/dryrun');
phutil_require_module('phabricator', 'applications/herald/controller/base');
phutil_require_module('phabricator', 'applications/herald/engine/engine');
phutil_require_module('phabricator', 'applications/herald/storage/rule');
phutil_require_module('phabricator', 'applications/repository/storage/commit');
phutil_require_module('phabricator', 'applications/repository/storage/repository');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'utils');
phutil_require_source('HeraldTestConsoleController.php');