mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Herald skeleton.
This commit is contained in:
parent
daf7a07064
commit
084c79d85a
44 changed files with 2089 additions and 0 deletions
|
@ -177,6 +177,27 @@ 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',
|
||||
'HeraldCondition' => 'applications/herald/storage/condition',
|
||||
'HeraldConditionConfig' => 'applications/herald/config/condition',
|
||||
'HeraldConditionTranscript' => 'applications/herald/storage/transcript/condition',
|
||||
'HeraldContentTypeConfig' => 'applications/herald/config/contenttype',
|
||||
'HeraldDAO' => 'applications/herald/storage/base',
|
||||
'HeraldEffect' => 'applications/herald/engine/effect',
|
||||
'HeraldEngine' => 'applications/herald/engine/engine',
|
||||
'HeraldFieldConfig' => 'applications/herald/config/field',
|
||||
'HeraldInvalidConditionException' => 'applications/herald/engine/engine/exception',
|
||||
'HeraldInvalidFieldException' => 'applications/herald/engine/engine/exception',
|
||||
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/object',
|
||||
'HeraldRecursiveConditionsException' => 'applications/herald/engine/engine/exception',
|
||||
'HeraldRule' => 'applications/herald/storage/rule',
|
||||
'HeraldRuleTranscript' => 'applications/herald/storage/transcript/rule',
|
||||
'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',
|
||||
|
@ -504,6 +525,12 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnFileContentQuery' => 'DiffusionFileContentQuery',
|
||||
'DiffusionSvnHistoryQuery' => 'DiffusionHistoryQuery',
|
||||
'DiffusionView' => 'AphrontView',
|
||||
'HeraldAction' => 'HeraldDAO',
|
||||
'HeraldApplyTranscript' => 'HeraldDAO',
|
||||
'HeraldCondition' => 'HeraldDAO',
|
||||
'HeraldDAO' => 'PhabricatorLiskDAO',
|
||||
'HeraldRule' => 'HeraldDAO',
|
||||
'HeraldTranscript' => 'HeraldDAO',
|
||||
'ManiphestController' => 'PhabricatorController',
|
||||
'ManiphestDAO' => 'PhabricatorLiskDAO',
|
||||
'ManiphestTask' => 'ManiphestDAO',
|
||||
|
@ -663,5 +690,9 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'requires_interface' =>
|
||||
array(
|
||||
'DryRunHeraldable' =>
|
||||
array(
|
||||
0 => 'IHeraldable',
|
||||
),
|
||||
),
|
||||
));
|
||||
|
|
72
src/applications/herald/config/action/HeraldActionConfig.php
Normal file
72
src/applications/herald/config/action/HeraldActionConfig.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?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 HeraldActionConfig {
|
||||
|
||||
const ACTION_ADD_CC = 'addcc';
|
||||
const ACTION_REMOVE_CC = 'remcc';
|
||||
const ACTION_EMAIL = 'email';
|
||||
const ACTION_NOTHING = 'nothing';
|
||||
|
||||
public static function getActionMap() {
|
||||
return array(
|
||||
self::ACTION_ADD_CC => 'Add emails to CC',
|
||||
self::ACTION_REMOVE_CC => 'Remove emails from CC',
|
||||
self::ACTION_EMAIL => 'Send an email to',
|
||||
self::ACTION_NOTHING => 'Do nothing',
|
||||
);
|
||||
}
|
||||
|
||||
public static function getActionMapForContentType($type) {
|
||||
$map = self::getActionMap();
|
||||
switch ($type) {
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::ACTION_ADD_CC,
|
||||
self::ACTION_REMOVE_CC,
|
||||
self::ACTION_NOTHING,
|
||||
));
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::ACTION_EMAIL,
|
||||
self::ACTION_NOTHING,
|
||||
));
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_MERGE:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::ACTION_EMAIL,
|
||||
self::ACTION_NOTHING,
|
||||
));
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::ACTION_EMAIL,
|
||||
self::ACTION_NOTHING,
|
||||
));
|
||||
default:
|
||||
throw new Exception("Unknown content type '{$type}'.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
src/applications/herald/config/action/__init__.php
Normal file
14
src/applications/herald/config/action/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/config/contenttype');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldActionConfig.php');
|
|
@ -0,0 +1,141 @@
|
|||
<?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 HeraldConditionConfig {
|
||||
|
||||
const CONDITION_CONTAINS = 'contains';
|
||||
const CONDITION_NOT_CONTAINS = '!contains';
|
||||
const CONDITION_IS = 'is';
|
||||
const CONDITION_IS_NOT = '!is';
|
||||
const CONDITION_IS_ANY = 'isany';
|
||||
const CONDITION_IS_NOT_ANY = '!isany';
|
||||
const CONDITION_INCLUDE_ALL = 'all';
|
||||
const CONDITION_INCLUDE_ANY = 'any';
|
||||
const CONDITION_INCLUDE_NONE = 'none';
|
||||
const CONDITION_IS_ME = 'me';
|
||||
const CONDITION_IS_NOT_ME = '!me';
|
||||
const CONDITION_REGEXP = 'regexp';
|
||||
const CONDITION_RULE = 'conditions';
|
||||
const CONDITION_NOT_RULE = '!conditions';
|
||||
const CONDITION_EXISTS = 'exists';
|
||||
const CONDITION_NOT_EXISTS = '!exists';
|
||||
const CONDITION_REGEXP_PAIR = 'regexp-pair';
|
||||
|
||||
public static function getConditionMap() {
|
||||
static $map = array(
|
||||
self::CONDITION_CONTAINS => 'contains',
|
||||
self::CONDITION_NOT_CONTAINS => 'does not contain',
|
||||
self::CONDITION_IS => 'is',
|
||||
self::CONDITION_IS_NOT => 'is not',
|
||||
self::CONDITION_IS_ANY => 'is any of',
|
||||
self::CONDITION_IS_NOT_ANY => 'is not any of',
|
||||
self::CONDITION_INCLUDE_ALL => 'include all of',
|
||||
self::CONDITION_INCLUDE_ANY => 'include any of',
|
||||
self::CONDITION_INCLUDE_NONE => 'include none of',
|
||||
self::CONDITION_IS_ME => 'is myself',
|
||||
self::CONDITION_IS_NOT_ME => 'is not myself',
|
||||
self::CONDITION_REGEXP => 'matches regexp',
|
||||
self::CONDITION_RULE => 'matches:',
|
||||
self::CONDITION_NOT_RULE => 'does not match:',
|
||||
self::CONDITION_EXISTS => 'exists',
|
||||
self::CONDITION_NOT_EXISTS => 'does not exist',
|
||||
self::CONDITION_REGEXP_PAIR => 'matches regexp pair',
|
||||
);
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
public static function getConditionMapForField($field) {
|
||||
$map = self::getConditionMap();
|
||||
switch ($field) {
|
||||
case HeraldFieldConfig::FIELD_TITLE:
|
||||
case HeraldFieldConfig::FIELD_BODY:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_CONTAINS,
|
||||
self::CONDITION_NOT_CONTAINS,
|
||||
self::CONDITION_IS,
|
||||
self::CONDITION_IS_NOT,
|
||||
self::CONDITION_REGEXP,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_AUTHOR:
|
||||
case HeraldFieldConfig::FIELD_REPOSITORY:
|
||||
case HeraldFieldConfig::FIELD_REVIEWER:
|
||||
case HeraldFieldConfig::FIELD_MERGE_REQUESTER:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_IS_ANY,
|
||||
self::CONDITION_IS_NOT_ANY,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_TAGS:
|
||||
case HeraldFieldConfig::FIELD_REVIEWERS:
|
||||
case HeraldFieldConfig::FIELD_CC:
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVIEWERS:
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_CCS:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_INCLUDE_ALL,
|
||||
self::CONDITION_INCLUDE_ANY,
|
||||
self::CONDITION_INCLUDE_NONE,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_DIFF_FILE:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_CONTAINS,
|
||||
self::CONDITION_REGEXP,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_DIFF_CONTENT:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_CONTAINS,
|
||||
self::CONDITION_REGEXP,
|
||||
self::CONDITION_REGEXP_PAIR,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_RULE:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_RULE,
|
||||
self::CONDITION_NOT_RULE,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE:
|
||||
case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_INCLUDE_ANY,
|
||||
self::CONDITION_INCLUDE_NONE,
|
||||
));
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVISION:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::CONDITION_EXISTS,
|
||||
self::CONDITION_NOT_EXISTS,
|
||||
));
|
||||
default:
|
||||
throw new Exception("Unknown field type '{$field}'.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
src/applications/herald/config/condition/__init__.php
Normal file
14
src/applications/herald/config/condition/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/config/field');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldConditionConfig.php');
|
|
@ -0,0 +1,35 @@
|
|||
<?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 HeraldContentTypeConfig {
|
||||
|
||||
const CONTENT_TYPE_DIFFERENTIAL = 'differential';
|
||||
const CONTENT_TYPE_COMMIT = 'commit';
|
||||
const CONTENT_TYPE_MERGE = 'merge';
|
||||
const CONTENT_TYPE_OWNERS = 'owners';
|
||||
|
||||
public static function getContentTypeMap() {
|
||||
static $map = array(
|
||||
self::CONTENT_TYPE_DIFFERENTIAL => 'Differential Revisions',
|
||||
self::CONTENT_TYPE_COMMIT => 'Commits',
|
||||
self::CONTENT_TYPE_MERGE => 'Merge Requests',
|
||||
self::CONTENT_TYPE_OWNERS => 'Owners Changes',
|
||||
);
|
||||
return $map;
|
||||
}
|
||||
}
|
10
src/applications/herald/config/contenttype/__init__.php
Normal file
10
src/applications/herald/config/contenttype/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('HeraldContentTypeConfig.php');
|
130
src/applications/herald/config/field/HeraldFieldConfig.php
Normal file
130
src/applications/herald/config/field/HeraldFieldConfig.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?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 HeraldFieldConfig {
|
||||
|
||||
const FIELD_TITLE = 'title';
|
||||
const FIELD_BODY = 'body';
|
||||
const FIELD_AUTHOR = 'author';
|
||||
const FIELD_REVIEWER = 'reviewer';
|
||||
const FIELD_REVIEWERS = 'reviewers';
|
||||
const FIELD_CC = 'cc';
|
||||
const FIELD_TAGS = 'tags';
|
||||
const FIELD_DIFF_FILE = 'diff-file';
|
||||
const FIELD_DIFF_CONTENT = 'diff-content';
|
||||
const FIELD_REPOSITORY = 'repository';
|
||||
const FIELD_RULE = 'rule';
|
||||
const FIELD_AFFECTED_PACKAGE = 'affected-package';
|
||||
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner';
|
||||
const FIELD_DIFFERENTIAL_REVISION = 'differential-revision';
|
||||
const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers';
|
||||
const FIELD_DIFFERENTIAL_CCS = 'differential-ccs';
|
||||
const FIELD_MERGE_REQUESTER = 'merge-requester';
|
||||
|
||||
public static function getFieldMap() {
|
||||
static $map = array(
|
||||
self::FIELD_TITLE => 'Title',
|
||||
self::FIELD_BODY => 'Body',
|
||||
self::FIELD_AUTHOR => 'Author',
|
||||
self::FIELD_REVIEWER => 'Reviewer',
|
||||
self::FIELD_REVIEWERS => 'Reviewers',
|
||||
self::FIELD_CC => 'CCs',
|
||||
self::FIELD_TAGS => 'Tags',
|
||||
self::FIELD_DIFF_FILE => 'Any changed filename',
|
||||
self::FIELD_DIFF_CONTENT => 'Any changed file content',
|
||||
self::FIELD_REPOSITORY => 'Repository',
|
||||
self::FIELD_RULE => 'Another Herald rule',
|
||||
self::FIELD_AFFECTED_PACKAGE => 'Any affected package',
|
||||
self::FIELD_AFFECTED_PACKAGE_OWNER => "Any affected package's owner",
|
||||
self::FIELD_DIFFERENTIAL_REVISION => 'Differential revision',
|
||||
self::FIELD_DIFFERENTIAL_REVIEWERS => 'Differential reviewers',
|
||||
self::FIELD_DIFFERENTIAL_CCS => 'Differential CCs',
|
||||
self::FIELD_MERGE_REQUESTER => 'Merge requester'
|
||||
);
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
public static function getFieldMapForContentType($type) {
|
||||
$map = self::getFieldMap();
|
||||
|
||||
switch ($type) {
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::FIELD_TITLE,
|
||||
self::FIELD_BODY,
|
||||
self::FIELD_AUTHOR,
|
||||
self::FIELD_REVIEWERS,
|
||||
self::FIELD_CC,
|
||||
self::FIELD_REPOSITORY,
|
||||
self::FIELD_DIFF_FILE,
|
||||
self::FIELD_DIFF_CONTENT,
|
||||
self::FIELD_RULE,
|
||||
self::FIELD_AFFECTED_PACKAGE,
|
||||
self::FIELD_AFFECTED_PACKAGE_OWNER,
|
||||
));
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::FIELD_BODY,
|
||||
self::FIELD_AUTHOR,
|
||||
self::FIELD_REVIEWER,
|
||||
self::FIELD_REPOSITORY,
|
||||
self::FIELD_DIFF_FILE,
|
||||
self::FIELD_DIFF_CONTENT,
|
||||
self::FIELD_RULE,
|
||||
self::FIELD_AFFECTED_PACKAGE,
|
||||
self::FIELD_AFFECTED_PACKAGE_OWNER,
|
||||
self::FIELD_DIFFERENTIAL_REVISION,
|
||||
self::FIELD_DIFFERENTIAL_REVIEWERS,
|
||||
self::FIELD_DIFFERENTIAL_CCS,
|
||||
));
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_MERGE:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::FIELD_BODY,
|
||||
self::FIELD_AUTHOR,
|
||||
self::FIELD_REVIEWER,
|
||||
self::FIELD_REPOSITORY,
|
||||
self::FIELD_DIFF_FILE,
|
||||
self::FIELD_DIFF_CONTENT,
|
||||
self::FIELD_RULE,
|
||||
self::FIELD_AFFECTED_PACKAGE,
|
||||
self::FIELD_AFFECTED_PACKAGE_OWNER,
|
||||
self::FIELD_DIFFERENTIAL_REVISION,
|
||||
self::FIELD_DIFFERENTIAL_REVIEWERS,
|
||||
self::FIELD_DIFFERENTIAL_CCS,
|
||||
self::FIELD_MERGE_REQUESTER,
|
||||
));
|
||||
case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS:
|
||||
return array_select_keys(
|
||||
$map,
|
||||
array(
|
||||
self::FIELD_AFFECTED_PACKAGE,
|
||||
self::FIELD_AFFECTED_PACKAGE_OWNER,
|
||||
));
|
||||
default:
|
||||
throw new Exception("Unknown content type.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
src/applications/herald/config/field/__init__.php
Normal file
14
src/applications/herald/config/field/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/config/contenttype');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldFieldConfig.php');
|
|
@ -0,0 +1,90 @@
|
|||
<?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 HeraldValueTypeConfig {
|
||||
|
||||
const VALUE_TEXT = 'text';
|
||||
const VALUE_NONE = 'none';
|
||||
const VALUE_EMAIL = 'email';
|
||||
const VALUE_USER = 'user';
|
||||
const VALUE_TAG = 'tag';
|
||||
const VALUE_RULE = 'rule';
|
||||
const VALUE_REPOSITORY = 'repository';
|
||||
const VALUE_OWNERS_PACKAGE = 'package';
|
||||
|
||||
public static function getValueTypeForFieldAndCondition($field, $condition) {
|
||||
switch ($condition) {
|
||||
case HeraldConditionConfig::CONDITION_CONTAINS:
|
||||
case HeraldConditionConfig::CONDITION_NOT_CONTAINS:
|
||||
case HeraldConditionConfig::CONDITION_IS:
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT:
|
||||
case HeraldConditionConfig::CONDITION_REGEXP:
|
||||
case HeraldConditionConfig::CONDITION_REGEXP_PAIR:
|
||||
return self::VALUE_TEXT;
|
||||
case HeraldConditionConfig::CONDITION_IS_ANY:
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT_ANY:
|
||||
switch ($field) {
|
||||
case HeraldFieldConfig::FIELD_REPOSITORY:
|
||||
return self::VALUE_REPOSITORY;
|
||||
default:
|
||||
return self::VALUE_USER;
|
||||
}
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_ALL:
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_ANY:
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_NONE:
|
||||
switch ($field) {
|
||||
case HeraldFieldConfig::FIELD_REPOSITORY:
|
||||
return self::VALUE_REPOSITORY;
|
||||
case HeraldFieldConfig::FIELD_CC:
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_CCS:
|
||||
return self::VALUE_EMAIL;
|
||||
case HeraldFieldConfig::FIELD_TAGS:
|
||||
return self::VALUE_TAG;
|
||||
case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE:
|
||||
return self::VALUE_OWNERS_PACKAGE;
|
||||
default:
|
||||
return self::VALUE_USER;
|
||||
}
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_ME:
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT_ME:
|
||||
case HeraldConditionConfig::CONDITION_EXISTS:
|
||||
case HeraldConditionConfig::CONDITION_NOT_EXISTS:
|
||||
return self::VALUE_NONE;
|
||||
case HeraldConditionConfig::CONDITION_RULE:
|
||||
case HeraldConditionConfig::CONDITION_NOT_RULE:
|
||||
return self::VALUE_RULE;
|
||||
default:
|
||||
throw new Exception("Unknown condition.");
|
||||
}
|
||||
}
|
||||
|
||||
public static function getValueTypeForAction($action) {
|
||||
switch ($action) {
|
||||
case HeraldActionConfig::ACTION_ADD_CC:
|
||||
case HeraldActionConfig::ACTION_REMOVE_CC:
|
||||
case HeraldActionConfig::ACTION_EMAIL:
|
||||
return self::VALUE_EMAIL;
|
||||
case HeraldActionConfig::ACTION_NOTHING:
|
||||
return self::VALUE_NONE;
|
||||
default:
|
||||
throw new Exception("Unknown action '{$action}'.");
|
||||
}
|
||||
}
|
||||
}
|
14
src/applications/herald/config/valuetype/__init__.php
Normal file
14
src/applications/herald/config/valuetype/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/config/action');
|
||||
phutil_require_module('phabricator', 'applications/herald/config/condition');
|
||||
phutil_require_module('phabricator', 'applications/herald/config/field');
|
||||
|
||||
|
||||
phutil_require_source('HeraldValueTypeConfig.php');
|
85
src/applications/herald/engine/effect/HeraldEffect.php
Normal file
85
src/applications/herald/engine/effect/HeraldEffect.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?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 HeraldEffect {
|
||||
|
||||
protected $objectID;
|
||||
protected $action;
|
||||
protected $target;
|
||||
|
||||
protected $ruleID;
|
||||
protected $effector;
|
||||
|
||||
protected $reason;
|
||||
|
||||
public function setObjectID($object_id) {
|
||||
$this->objectID = $object_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectID() {
|
||||
return $this->objectID;
|
||||
}
|
||||
|
||||
public function setAction($action) {
|
||||
$this->action = $action;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction() {
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function setTarget($target) {
|
||||
$this->target = $target;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTarget() {
|
||||
return $this->target;
|
||||
}
|
||||
|
||||
public function setRuleID($rule_id) {
|
||||
$this->ruleID = $rule_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRuleID() {
|
||||
return $this->ruleID;
|
||||
}
|
||||
|
||||
public function setEffector($effector) {
|
||||
$this->effector = $effector;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEffector() {
|
||||
return $this->effector;
|
||||
}
|
||||
|
||||
public function setReason($reason) {
|
||||
$this->reason = $reason;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
}
|
||||
|
10
src/applications/herald/engine/effect/__init__.php
Normal file
10
src/applications/herald/engine/effect/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('HeraldEffect.php');
|
447
src/applications/herald/engine/engine/HeraldEngine.php
Normal file
447
src/applications/herald/engine/engine/HeraldEngine.php
Normal file
|
@ -0,0 +1,447 @@
|
|||
<?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 HeraldEngine {
|
||||
|
||||
protected $rules = array();
|
||||
protected $results = array();
|
||||
protected $stack = array();
|
||||
protected $activeRule = null;
|
||||
|
||||
protected $fieldCache = array();
|
||||
protected $object = null;
|
||||
|
||||
public static function loadAndApplyRules(IHeraldable $object) {
|
||||
$content_type = $object->getHeraldTypeName();
|
||||
$rules = HeraldRule::loadAllByContentTypeWithFullData($content_type);
|
||||
|
||||
$engine = new HeraldEngine();
|
||||
$effects = $engine->applyRules($rules, $object);
|
||||
$engine->applyEffects($effects, $object);
|
||||
|
||||
return $engine->getTranscript();
|
||||
}
|
||||
|
||||
public function applyRules(array $rules, IHeraldable $object) {
|
||||
$t_start = microtime(true);
|
||||
|
||||
$rules = mpull($rules, null, 'getID');
|
||||
|
||||
$this->transcript = new HeraldTranscript();
|
||||
$this->transcript->setObjectID((string)$object->getFBID());
|
||||
$this->fieldCache = array();
|
||||
$this->results = array();
|
||||
$this->rules = $rules;
|
||||
$this->object = $object;
|
||||
|
||||
$effects = array();
|
||||
foreach ($rules as $id => $rule) {
|
||||
|
||||
|
||||
$this->stack = array();
|
||||
try {
|
||||
$rule_matches = $this->doesRuleMatch($rule, $object);
|
||||
} catch (HeraldRecursiveConditionsException $ex) {
|
||||
$names = array();
|
||||
foreach ($this->stack as $rule_id => $ignored) {
|
||||
$names[] = '"'.$rules[$rule_id]->getName().'"';
|
||||
}
|
||||
$names = implode(', ', $names);
|
||||
foreach ($this->stack as $rule_id => $ignored) {
|
||||
$xscript = new HeraldRuleTranscript();
|
||||
$xscript->setRuleID($rule_id);
|
||||
$xscript->setResult(false);
|
||||
$xscript->setReason(
|
||||
"Rules {$names} are recursively dependent upon one another! ".
|
||||
"Don't do this! You have formed an unresolvable cycle in the ".
|
||||
"dependency graph!");
|
||||
$xscript->setRuleName($rules[$rule_id]->getName());
|
||||
$xscript->setRuleOwner($rules[$rule_id]->getOwnerID());
|
||||
$this->transcript->addRuleTranscript($xscript);
|
||||
}
|
||||
$rule_matches = false;
|
||||
}
|
||||
$this->results[$id] = $rule_matches;
|
||||
|
||||
if ($rule_matches) {
|
||||
foreach ($this->getRuleEffects($rule, $object) as $effect) {
|
||||
$effects[] = $effect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$object_transcript = new HeraldObjectTranscript();
|
||||
$object_transcript->setFBID($object->getFBID());
|
||||
$object_transcript->setName($object->getHeraldName());
|
||||
$object_transcript->setType($object->getHeraldTypeName());
|
||||
$object_transcript->setFields($this->fieldCache);
|
||||
|
||||
$this->transcript->setObjectTranscript($object_transcript);
|
||||
|
||||
$t_end = microtime(true);
|
||||
|
||||
$this->transcript->setDuration($t_end - $t_start);
|
||||
|
||||
return $effects;
|
||||
}
|
||||
|
||||
public function applyEffects(array $effects, IHeraldable $object) {
|
||||
if ($object instanceof DryRunHeraldable) {
|
||||
$this->transcript->setDryRun(true);
|
||||
} else {
|
||||
$this->transcript->setDryRun(false);
|
||||
}
|
||||
foreach ($object->applyHeraldEffects($effects) as $apply_xscript) {
|
||||
if (!($apply_xscript instanceof HeraldApplyTranscript)) {
|
||||
throw new Exception(
|
||||
"Heraldable must return HeraldApplyTranscripts from ".
|
||||
"applyHeraldEffect().");
|
||||
}
|
||||
$this->transcript->addApplyTranscript($apply_xscript);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTranscript() {
|
||||
$this->transcript->save();
|
||||
return $this->transcript;
|
||||
}
|
||||
|
||||
protected function doesRuleMatch(HeraldRule $rule, IHeraldable $object) {
|
||||
$id = $rule->getID();
|
||||
|
||||
if (isset($this->results[$id])) {
|
||||
// If we've already evaluated this rule because another rule depends
|
||||
// on it, we don't need to reevaluate it.
|
||||
return $this->results[$id];
|
||||
}
|
||||
|
||||
if (isset($this->stack[$id])) {
|
||||
// We've recursed, fail all of the rules on the stack. This happens when
|
||||
// there's a dependency cycle with "Rule conditions match for rule ..."
|
||||
// conditions.
|
||||
foreach ($this->stack as $rule_id => $ignored) {
|
||||
$this->results[$rule_id] = false;
|
||||
}
|
||||
throw new HeraldRecursiveConditionsException();
|
||||
}
|
||||
|
||||
$this->stack[$id] = true;
|
||||
|
||||
$all = $rule->getMustMatchAll();
|
||||
|
||||
$conditions = $rule->getConditions();
|
||||
|
||||
$result = null;
|
||||
|
||||
$local_version = id(new HeraldRule())->getConfigVersion();
|
||||
if ($rule->getConfigVersion() > $local_version) {
|
||||
$reason = "Rule could not be processed, it was created with a newer ".
|
||||
"version of Herald.";
|
||||
$result = false;
|
||||
} else if (!$conditions) {
|
||||
$reason = "Rule failed automatically because it has no conditions.";
|
||||
$result = false;
|
||||
/* TOOD: Restore this in some form?
|
||||
} else if (!is_fb_employee($rule->getOwnerID())) {
|
||||
$reason = "Rule failed automatically because its owner is not an ".
|
||||
"active employee.";
|
||||
$result = false;
|
||||
*/
|
||||
} else {
|
||||
foreach ($conditions as $condition) {
|
||||
$match = $this->doesConditionMatch($rule, $condition, $object);
|
||||
|
||||
if (!$all && $match) {
|
||||
$reason = "Any condition matched.";
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($all && !$match) {
|
||||
$reason = "Not all conditions matched.";
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($result === null) {
|
||||
if ($all) {
|
||||
$reason = "All conditions matched.";
|
||||
$result = true;
|
||||
} else {
|
||||
$reason = "No conditions matched.";
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rule_transcript = new HeraldRuleTranscript();
|
||||
$rule_transcript->setRuleID($rule->getID());
|
||||
$rule_transcript->setResult($result);
|
||||
$rule_transcript->setReason($reason);
|
||||
$rule_transcript->setRuleName($rule->getName());
|
||||
$rule_transcript->setRuleOwner($rule->getOwnerID());
|
||||
|
||||
$this->transcript->addRuleTranscript($rule_transcript);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function doesConditionMatch(
|
||||
HeraldRule $rule,
|
||||
HeraldCondition $condition,
|
||||
IHeraldable $object) {
|
||||
|
||||
$object_value = $this->getConditionObjectValue($condition, $object);
|
||||
$test_value = $condition->getValue();
|
||||
|
||||
$cond = $condition->getCondition();
|
||||
|
||||
$transcript = new HeraldConditionTranscript();
|
||||
$transcript->setRuleID($rule->getID());
|
||||
$transcript->setConditionID($condition->getID());
|
||||
$transcript->setFieldName($condition->getFieldName());
|
||||
$transcript->setCondition($cond);
|
||||
$transcript->setTestValue($test_value);
|
||||
|
||||
$result = null;
|
||||
switch ($cond) {
|
||||
case HeraldConditionConfig::CONDITION_CONTAINS:
|
||||
// "Contains" can take an array of strings, as in "Any changed
|
||||
// filename" for diffs.
|
||||
foreach ((array)$object_value as $value) {
|
||||
$result = (stripos($value, $test_value) !== false);
|
||||
if ($result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_NOT_CONTAINS:
|
||||
$result = (stripos($object_value, $test_value) === false);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS:
|
||||
$result = ($object_value == $test_value);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT:
|
||||
$result = ($object_value != $test_value);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_ME:
|
||||
$result = ($object_value == $rule->getOwnerID());
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT_ME:
|
||||
$result = ($object_value != $rule->getOwnerID());
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_ANY:
|
||||
$test_value = array_flip($test_value);
|
||||
$result = isset($test_value[$object_value]);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT_ANY:
|
||||
$test_value = array_flip($test_value);
|
||||
$result = !isset($test_value[$object_value]);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_ALL:
|
||||
if (!is_array($object_value)) {
|
||||
$transcript->setNote('Object produced bad value!');
|
||||
$result = false;
|
||||
} else {
|
||||
$have = array_select_keys(array_flip($object_value),
|
||||
$test_value);
|
||||
$result = (count($have) == count($test_value));
|
||||
}
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_ANY:
|
||||
$result = (bool)array_select_keys(array_flip($object_value),
|
||||
$test_value);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_NONE:
|
||||
$result = !array_select_keys(array_flip($object_value),
|
||||
$test_value);
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_EXISTS:
|
||||
$result = (bool)$object_value;
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_NOT_EXISTS:
|
||||
$result = !$object_value;
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_REGEXP:
|
||||
foreach ((array)$object_value as $value) {
|
||||
$result = @preg_match($test_value, $value);
|
||||
if ($result === false) {
|
||||
$transcript->setNote(
|
||||
"Regular expression is not valid!");
|
||||
break;
|
||||
}
|
||||
if ($result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$result = (bool)$result;
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_REGEXP_PAIR:
|
||||
// Match a JSON-encoded pair of regular expressions against a
|
||||
// dictionary. The first regexp must match the dictionary key, and the
|
||||
// second regexp must match the dictionary value. If any key/value pair
|
||||
// in the dictionary matches both regexps, the condition is satisfied.
|
||||
$regexp_pair = json_decode($test_value, true);
|
||||
if (!is_array($regexp_pair)) {
|
||||
$result = false;
|
||||
$transcript->setNote("Regular expression pair is not valid JSON!");
|
||||
break;
|
||||
}
|
||||
if (count($regexp_pair) != 2) {
|
||||
$result = false;
|
||||
$transcript->setNote("Regular expression pair is not a pair!");
|
||||
break;
|
||||
}
|
||||
|
||||
$key_regexp = array_shift($regexp_pair);
|
||||
$value_regexp = array_shift($regexp_pair);
|
||||
|
||||
foreach ((array)$object_value as $key => $value) {
|
||||
$key_matches = @preg_match($key_regexp, $key);
|
||||
if ($key_matches === false) {
|
||||
$result = false;
|
||||
$transcript->setNote("First regular expression is invalid!");
|
||||
break 2;
|
||||
}
|
||||
if ($key_matches) {
|
||||
$value_matches = @preg_match($value_regexp, $value);
|
||||
if ($value_matches === false) {
|
||||
$result = false;
|
||||
$transcript->setNote("Second regular expression is invalid!");
|
||||
break 2;
|
||||
}
|
||||
if ($value_matches) {
|
||||
$result = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = false;
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_RULE:
|
||||
case HeraldConditionConfig::CONDITION_NOT_RULE:
|
||||
|
||||
$rule = idx($this->rules, $test_value);
|
||||
if (!$rule) {
|
||||
$transcript->setNote(
|
||||
"Condition references a rule which does not exist!");
|
||||
$result = false;
|
||||
} else {
|
||||
$is_not = ($cond == HeraldConditionConfig::CONDITION_NOT_RULE);
|
||||
$result = $this->doesRuleMatch($rule, $object);
|
||||
if ($is_not) {
|
||||
$result = !$result;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new HeraldInvalidConditionException(
|
||||
"Unknown condition '{$cond}'.");
|
||||
}
|
||||
|
||||
$transcript->setResult($result);
|
||||
|
||||
$this->transcript->addConditionTranscript($transcript);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getConditionObjectValue(
|
||||
HeraldCondition $condition,
|
||||
IHeraldable $object) {
|
||||
|
||||
$field = $condition->getFieldName();
|
||||
|
||||
return $this->getObjectFieldValue($field);
|
||||
}
|
||||
|
||||
public function getObjectFieldValue($field) {
|
||||
if (isset($this->fieldCache[$field])) {
|
||||
return $this->fieldCache[$field];
|
||||
}
|
||||
|
||||
$result = null;
|
||||
switch ($field) {
|
||||
case HeraldFieldConfig::FIELD_RULE:
|
||||
$result = null;
|
||||
break;
|
||||
case HeraldFieldConfig::FIELD_TITLE:
|
||||
case HeraldFieldConfig::FIELD_BODY:
|
||||
case HeraldFieldConfig::FIELD_DIFF_FILE:
|
||||
case HeraldFieldConfig::FIELD_DIFF_CONTENT:
|
||||
// TODO: Type should be string.
|
||||
$result = $this->object->getHeraldField($field);
|
||||
break;
|
||||
case HeraldFieldConfig::FIELD_AUTHOR:
|
||||
case HeraldFieldConfig::FIELD_REPOSITORY:
|
||||
case HeraldFieldConfig::FIELD_MERGE_REQUESTER:
|
||||
// TODO: Type should be fbid.
|
||||
$result = $this->object->getHeraldField($field);
|
||||
break;
|
||||
case HeraldFieldConfig::FIELD_TAGS:
|
||||
case HeraldFieldConfig::FIELD_REVIEWER:
|
||||
case HeraldFieldConfig::FIELD_REVIEWERS:
|
||||
case HeraldFieldConfig::FIELD_CC:
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVIEWERS:
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_CCS:
|
||||
// TODO: Type should be list.
|
||||
$result = $this->object->getHeraldField($field);
|
||||
break;
|
||||
case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE:
|
||||
case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER:
|
||||
$result = $this->object->getHeraldField($field);
|
||||
if (!is_array($result)) {
|
||||
throw new HeraldInvalidFieldException(
|
||||
"Value of field type {$field} is not an array!");
|
||||
}
|
||||
break;
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVISION:
|
||||
// TODO: Type should be boolean I guess.
|
||||
$result = $this->object->getHeraldField($field);
|
||||
break;
|
||||
default:
|
||||
throw new HeraldInvalidConditionException(
|
||||
"Unknown field type '{$field}'!");
|
||||
}
|
||||
|
||||
$this->fieldCache[$field] = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRuleEffects(HeraldRule $rule, IHeraldable $object) {
|
||||
$effects = array();
|
||||
foreach ($rule->getActions() as $action) {
|
||||
$effect = new HeraldEffect();
|
||||
$effect->setObjectID($object->getFBID());
|
||||
$effect->setAction($action->getAction());
|
||||
$effect->setTarget($action->getTarget());
|
||||
|
||||
$effect->setRuleID($rule->getID());
|
||||
|
||||
$name = $rule->getName();
|
||||
$id = $rule->getID();
|
||||
$effect->setReason(
|
||||
'Conditions were met for Herald rule "'.$name.'" (#'.$id.').');
|
||||
|
||||
$effects[] = $effect;
|
||||
}
|
||||
return $effects;
|
||||
}
|
||||
|
||||
}
|
22
src/applications/herald/engine/engine/__init__.php
Normal file
22
src/applications/herald/engine/engine/__init__.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/config/condition');
|
||||
phutil_require_module('phabricator', 'applications/herald/config/field');
|
||||
phutil_require_module('phabricator', 'applications/herald/engine/effect');
|
||||
phutil_require_module('phabricator', 'applications/herald/engine/engine/exception');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/rule');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/transcript/base');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/transcript/condition');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/transcript/object');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/transcript/rule');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldEngine.php');
|
|
@ -0,0 +1,19 @@
|
|||
<?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 HeraldInvalidConditionException extends Exception {}
|
|
@ -0,0 +1,19 @@
|
|||
<?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 HeraldInvalidFieldException extends Exception {}
|
|
@ -0,0 +1,19 @@
|
|||
<?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 HeraldRecursiveConditionsException extends Exception {}
|
12
src/applications/herald/engine/engine/exception/__init__.php
Normal file
12
src/applications/herald/engine/engine/exception/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('HeraldInvalidConditionException.php');
|
||||
phutil_require_source('HeraldInvalidFieldException.php');
|
||||
phutil_require_source('HeraldRecursiveConditionsException.php');
|
28
src/applications/herald/heraldable/base/IHeraldable.php
Normal file
28
src/applications/herald/heraldable/base/IHeraldable.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
interface IHeraldable {
|
||||
|
||||
public function getFBID();
|
||||
public function getHeraldName();
|
||||
public function getHeraldTypeName();
|
||||
public function getHeraldField($field_name);
|
||||
public function applyHeraldEffects(array $effects);
|
||||
|
||||
}
|
||||
|
10
src/applications/herald/heraldable/base/__init__.php
Normal file
10
src/applications/herald/heraldable/base/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('IHeraldable.php');
|
|
@ -0,0 +1,47 @@
|
|||
<?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 DryRunHeraldable implements IHeraldable {
|
||||
|
||||
public function getFBID() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getHeraldName() {
|
||||
return 'Dry Run';
|
||||
}
|
||||
|
||||
public function getHeraldTypeName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getHeraldField($field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function applyHeraldEffects(array $effects) {
|
||||
$results = array();
|
||||
foreach ($effects as $effect) {
|
||||
$results[] = new HeraldApplyTranscript(
|
||||
$effect,
|
||||
false,
|
||||
'This was a dry run, so no actions were actually taken.');
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
13
src/applications/herald/heraldable/dryrun/__init__.php
Normal file
13
src/applications/herald/heraldable/dryrun/__init__.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/heraldable/base');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/transcript/apply');
|
||||
|
||||
|
||||
phutil_require_source('DryRunHeraldable.php');
|
35
src/applications/herald/storage/action/HeraldAction.php
Normal file
35
src/applications/herald/storage/action/HeraldAction.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?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 HeraldAction extends HeraldDAO {
|
||||
|
||||
protected $ruleID;
|
||||
|
||||
protected $action;
|
||||
protected $target;
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_SERIALIZATION => array(
|
||||
'target' => self::SERIALIZATION_JSON,
|
||||
)
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
|
||||
}
|
12
src/applications/herald/storage/action/__init__.php
Normal file
12
src/applications/herald/storage/action/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/base');
|
||||
|
||||
|
||||
phutil_require_source('HeraldAction.php');
|
25
src/applications/herald/storage/base/HeraldDAO.php
Normal file
25
src/applications/herald/storage/base/HeraldDAO.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
abstract class HeraldDAO extends PhabricatorLiskDAO {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'herald';
|
||||
}
|
||||
|
||||
}
|
10
src/applications/herald/storage/base/__init__.php
Normal file
10
src/applications/herald/storage/base/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/base/storage/lisk');
|
||||
|
||||
phutil_require_source('HeraldDAO.php');
|
|
@ -0,0 +1,35 @@
|
|||
<?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 HeraldCondition extends HeraldDAO {
|
||||
|
||||
protected $ruleID;
|
||||
|
||||
protected $fieldName;
|
||||
protected $condition;
|
||||
protected $value;
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_SERIALIZATION => array(
|
||||
'value' => self::SERIALIZATION_JSON,
|
||||
)
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
}
|
12
src/applications/herald/storage/condition/__init__.php
Normal file
12
src/applications/herald/storage/condition/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/base');
|
||||
|
||||
|
||||
phutil_require_source('HeraldCondition.php');
|
141
src/applications/herald/storage/rule/HeraldRule.php
Normal file
141
src/applications/herald/storage/rule/HeraldRule.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?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 HeraldRule extends HeraldDAO {
|
||||
|
||||
protected $name;
|
||||
protected $ownerID;
|
||||
|
||||
protected $contentType;
|
||||
protected $mustMatchAll;
|
||||
|
||||
protected $configVersion = 7;
|
||||
|
||||
public static function loadAllByContentTypeWithFullData($content_type) {
|
||||
$rules = id(new HeraldRule())->loadAllWhere(
|
||||
'contentType = %s',
|
||||
$content_type);
|
||||
$rule_ids = mpull($rules, 'getID');
|
||||
|
||||
$conditions = id(new HeraldCondition())->loadAllWhere(
|
||||
'ruleID in (%Ld)',
|
||||
$rule_ids);
|
||||
|
||||
$actions = id(new HeraldAction())->loadAllWhere(
|
||||
'ruleID in (%Ld)',
|
||||
$rule_ids);
|
||||
|
||||
$conditions = mgroup($conditions, 'getRuleID');
|
||||
$actions = mgroup($actions, 'getRuleID');
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
$rule->attachConditions(idx($conditions, $rule->getID(), array()));
|
||||
$rule->attachActions(idx($actions, $rule->getID(), array()));
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function loadConditions() {
|
||||
if (!$this->getID()) {
|
||||
return array();
|
||||
}
|
||||
return id(new HeraldCondition())->loadAllWhere(
|
||||
'ruleID = %d',
|
||||
$this->getID());
|
||||
}
|
||||
|
||||
public function attachConditions(array $conditions) {
|
||||
$this->conditions = $conditions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConditions() {
|
||||
// TODO: validate conditions have been attached.
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
public function loadActions() {
|
||||
if (!$this->getID()) {
|
||||
return array();
|
||||
}
|
||||
return id(new HeraldAction())->loadAllWhere(
|
||||
'ruleID = %d',
|
||||
$this->getID());
|
||||
}
|
||||
|
||||
public function attachActions(array $actions) {
|
||||
// TODO: validate actions have been attached.
|
||||
$this->actions = $actions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActions() {
|
||||
return $this->actions;
|
||||
}
|
||||
|
||||
public function saveConditions(array $conditions) {
|
||||
return $this->saveChildren(
|
||||
id(new HeraldCondition())->getTableName(),
|
||||
$conditions);
|
||||
}
|
||||
|
||||
public function saveActions(array $actions) {
|
||||
return $this->saveChildren(
|
||||
id(new HeraldAction())->getTableName(),
|
||||
$actions);
|
||||
}
|
||||
|
||||
protected function saveChildren($table_name, array $children) {
|
||||
if (!$this->getID()) {
|
||||
throw new Exception("Save rule before saving children.");
|
||||
}
|
||||
|
||||
foreach ($children as $child) {
|
||||
$child->setRuleID($this->getID());
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// $this->openTransaction();
|
||||
$this->getLink('w')->query(
|
||||
'DELETE FROM %T WHERE ruleID = %d',
|
||||
$table_name,
|
||||
$this->getID());
|
||||
foreach ($children as $child) {
|
||||
$child->save();
|
||||
}
|
||||
// $this->saveTransaction();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
|
||||
// TODO:
|
||||
// $this->openTransaction();
|
||||
$this->getLink('w')->query(
|
||||
'DELETE FROM %T WHERE ruleID = %d',
|
||||
id(new HeraldCondition())->getTableName(),
|
||||
$this->getID());
|
||||
$this->getLink('w')->query(
|
||||
'DELETE FROM %T WHERE ruleID = %d',
|
||||
id(new HeraldAction())->getTableName(),
|
||||
$this->getID());
|
||||
parent::delete();
|
||||
// $this->saveTransaction();
|
||||
}
|
||||
|
||||
}
|
16
src/applications/herald/storage/rule/__init__.php
Normal file
16
src/applications/herald/storage/rule/__init__.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/action');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/base');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/condition');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldRule.php');
|
|
@ -0,0 +1,80 @@
|
|||
<?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 HeraldApplyTranscript extends HeraldDAO {
|
||||
|
||||
protected $action;
|
||||
protected $target;
|
||||
|
||||
protected $ruleID;
|
||||
protected $effector;
|
||||
|
||||
protected $reason;
|
||||
|
||||
protected $applied;
|
||||
protected $appliedReason;
|
||||
|
||||
public function __construct(
|
||||
HeraldEffect $effect,
|
||||
$applied,
|
||||
$reason = null) {
|
||||
|
||||
$this->setAction($effect->getAction());
|
||||
$this->setTarget($effect->getTarget());
|
||||
$this->setRuleID($effect->getRuleID());
|
||||
$this->setEffector($effect->getEffector());
|
||||
$this->setReason($effect->getReason());
|
||||
$this->setApplied($applied);
|
||||
$this->setAppliedReason($reason);
|
||||
|
||||
}
|
||||
|
||||
public function getAction() {
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function getTarget() {
|
||||
return $this->target;
|
||||
}
|
||||
|
||||
public function getRuleID() {
|
||||
return $this->ruleID;
|
||||
}
|
||||
|
||||
public function getEffector() {
|
||||
return $this->effector;
|
||||
}
|
||||
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
public function getApplied() {
|
||||
return $this->applied;
|
||||
}
|
||||
|
||||
public function setAppliedReason($applied_reason) {
|
||||
$this->appliedReason = $applied_reason;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAppliedReason() {
|
||||
return $this->appliedReason;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/base');
|
||||
|
||||
|
||||
phutil_require_source('HeraldApplyTranscript.php');
|
|
@ -0,0 +1,144 @@
|
|||
<?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 HeraldTranscript extends HeraldDAO {
|
||||
|
||||
protected $id;
|
||||
protected $fbid;
|
||||
|
||||
protected $objectTranscript;
|
||||
protected $ruleTranscripts = array();
|
||||
protected $conditionTranscripts = array();
|
||||
protected $applyTranscripts = array();
|
||||
|
||||
protected $time;
|
||||
protected $host;
|
||||
protected $path;
|
||||
protected $duration;
|
||||
|
||||
protected $objectID;
|
||||
protected $dryRun;
|
||||
|
||||
public function getXHeraldRulesHeader() {
|
||||
$ids = array();
|
||||
foreach ($this->applyTranscripts as $xscript) {
|
||||
if ($xscript->getApplied()) {
|
||||
if ($xscript->getRuleID()) {
|
||||
$ids[] = $xscript->getRuleID();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$ids) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
// A rule may have multiple effects, which will cause it to be listed
|
||||
// multiple times.
|
||||
$ids = array_unique($ids);
|
||||
|
||||
foreach ($ids as $k => $id) {
|
||||
$ids[$k] = '<'.$id.'>';
|
||||
}
|
||||
|
||||
return implode(', ', $ids);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
// Ugh. Too much of a mess to deal with.
|
||||
return array(
|
||||
self::CONFIG_AUX_FBID => 'HERALD_TRANSCRIPT',
|
||||
self::CONFIG_SERIALIZATION => array(
|
||||
'objectTranscript' => self::SERIALIZATION_PHP,
|
||||
'ruleTranscripts' => self::SERIALIZATION_PHP,
|
||||
'conditionTranscripts' => self::SERIALIZATION_PHP,
|
||||
'applyTranscripts' => self::SERIALIZATION_PHP,
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->time = time();
|
||||
$this->host = php_uname('n');
|
||||
$this->path = realpath($_SERVER['PHP_ROOT']);
|
||||
}
|
||||
|
||||
public function addApplyTranscript(HeraldApplyTranscript $transcript) {
|
||||
$this->applyTranscripts[] = $transcript;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getApplyTranscripts() {
|
||||
return nonempty($this->applyTranscripts, array());
|
||||
}
|
||||
|
||||
public function setDuration($duration) {
|
||||
$this->duration = $duration;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setObjectTranscript(HeraldObjectTranscript $transcript) {
|
||||
$this->objectTranscript = $transcript;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectTranscript() {
|
||||
return $this->objectTranscript;
|
||||
}
|
||||
|
||||
public function addRuleTranscript(HeraldRuleTranscript $transcript) {
|
||||
$this->ruleTranscripts[$transcript->getRuleID()] = $transcript;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function discardDetails() {
|
||||
$this->applyTranscripts = null;
|
||||
$this->ruleTranscripts = null;
|
||||
$this->objectTranscript = null;
|
||||
$this->conditionTranscripts = null;
|
||||
}
|
||||
|
||||
public function getRuleTranscripts() {
|
||||
return nonempty($this->ruleTranscripts, array());
|
||||
}
|
||||
|
||||
public function addConditionTranscript(
|
||||
HeraldConditionTranscript $transcript) {
|
||||
$rule_id = $transcript->getRuleID();
|
||||
$cond_id = $transcript->getConditionID();
|
||||
|
||||
$this->conditionTranscripts[$rule_id][$cond_id] = $transcript;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConditionTranscriptsForRule($rule_id) {
|
||||
return idx($this->conditionTranscripts, $rule_id, array());
|
||||
}
|
||||
|
||||
public function getMetadataMap() {
|
||||
return array(
|
||||
'Run At Epoch' => date('F jS, g:i A', $this->time),
|
||||
'Run On Host' => $this->host.':'.$this->path,
|
||||
'Run Duration' => (int)(1000 * $this->duration).' ms',
|
||||
);
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
return 'http://tools.facebook.com/herald/transcript/'.$this->getID().'/';
|
||||
}
|
||||
|
||||
}
|
14
src/applications/herald/storage/transcript/base/__init__.php
Normal file
14
src/applications/herald/storage/transcript/base/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/base');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldTranscript.php');
|
|
@ -0,0 +1,91 @@
|
|||
<?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 HeraldConditionTranscript {
|
||||
|
||||
protected $ruleID;
|
||||
protected $conditionID;
|
||||
protected $fieldName;
|
||||
protected $condition;
|
||||
protected $testValue;
|
||||
protected $note;
|
||||
protected $result;
|
||||
|
||||
public function setRuleID($rule_id) {
|
||||
$this->ruleID = $rule_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRuleID() {
|
||||
return $this->ruleID;
|
||||
}
|
||||
|
||||
public function setConditionID($condition_id) {
|
||||
$this->conditionID = $condition_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConditionID() {
|
||||
return $this->conditionID;
|
||||
}
|
||||
|
||||
public function setFieldName($field_name) {
|
||||
$this->fieldName = $field_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return $this->fieldName;
|
||||
}
|
||||
|
||||
public function setCondition($condition) {
|
||||
$this->condition = $condition;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCondition() {
|
||||
return $this->condition;
|
||||
}
|
||||
|
||||
public function setTestValue($test_value) {
|
||||
$this->testValue = $test_value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTestValue() {
|
||||
return $this->testValue;
|
||||
}
|
||||
|
||||
public function setNote($note) {
|
||||
$this->note = $note;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNote() {
|
||||
return $this->note;
|
||||
}
|
||||
|
||||
public function setResult($result) {
|
||||
$this->result = $result;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult() {
|
||||
return $this->result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('HeraldConditionTranscript.php');
|
|
@ -0,0 +1,61 @@
|
|||
<?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 HeraldObjectTranscript {
|
||||
|
||||
protected $fbid;
|
||||
protected $type;
|
||||
protected $name;
|
||||
protected $fields;
|
||||
|
||||
public function setFBID($fbid) {
|
||||
$this->fbid = $fbid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFBID() {
|
||||
return $this->fbid;
|
||||
}
|
||||
|
||||
public function setType($type) {
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setFields(array $fields) {
|
||||
$this->fields = $fields;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFields() {
|
||||
return $this->fields;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('HeraldObjectTranscript.php');
|
|
@ -0,0 +1,72 @@
|
|||
<?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 HeraldRuleTranscript {
|
||||
|
||||
protected $ruleID;
|
||||
protected $result;
|
||||
protected $reason;
|
||||
|
||||
protected $ruleName;
|
||||
protected $ruleOwner;
|
||||
|
||||
public function setResult($result) {
|
||||
$this->result = $result;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult() {
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function setReason($reason) {
|
||||
$this->reason = $reason;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
public function setRuleID($rule_id) {
|
||||
$this->ruleID = $rule_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRuleID() {
|
||||
return $this->ruleID;
|
||||
}
|
||||
|
||||
public function setRuleName($rule_name) {
|
||||
$this->ruleName = $rule_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRuleName() {
|
||||
return $this->ruleName;
|
||||
}
|
||||
|
||||
public function setRuleOwner($rule_owner) {
|
||||
$this->ruleOwner = $rule_owner;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRuleOwner() {
|
||||
return $this->ruleOwner;
|
||||
}
|
||||
}
|
10
src/applications/herald/storage/transcript/rule/__init__.php
Normal file
10
src/applications/herald/storage/transcript/rule/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('HeraldRuleTranscript.php');
|
|
@ -9,6 +9,7 @@
|
|||
phutil_require_module('phabricator', 'applications/files/uri');
|
||||
phutil_require_module('phabricator', 'applications/phid/constants');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
phutil_require_module('phutil', 'symbols');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
|
|
@ -10,6 +10,7 @@ phutil_require_module('phabricator', 'applications/repository/worker/commitmessa
|
|||
phutil_require_module('phabricator', 'infrastructure/daemon/workers/storage/task');
|
||||
|
||||
phutil_require_module('phutil', 'future/exec');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorRepositorySvnCommitMessageParserWorker.php');
|
||||
|
|
|
@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/phid/handle/data');
|
|||
phutil_require_module('phabricator', 'applications/search/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/search/execute/mysql');
|
||||
phutil_require_module('phabricator', 'applications/search/storage/query');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
|
Loading…
Reference in a new issue