mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Automatically support "Add Projects" in Herald for all relevant objects
Summary: Ref T7849. If the adapted object implements `PhabricatorProjectInterface`, support the ADD_PROJECTS action. Test Plan: - Wrote a Differential rule with "Add Projects". - Updated a revision. - Got projects added. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7849 Differential Revision: https://secure.phabricator.com/D12504
This commit is contained in:
parent
501630d931
commit
959e9d9ac2
6 changed files with 56 additions and 32 deletions
|
@ -244,7 +244,7 @@ abstract class HeraldAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function newTransaction() {
|
protected function newTransaction() {
|
||||||
$object = $this->getObject();
|
$object = $this->newObject();
|
||||||
|
|
||||||
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
|
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -258,8 +258,6 @@ abstract class HeraldAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NOTE: You generally should not override this; it exists to support legacy
|
* NOTE: You generally should not override this; it exists to support legacy
|
||||||
* adapters which had hard-coded content types.
|
* adapters which had hard-coded content types.
|
||||||
|
@ -273,6 +271,26 @@ abstract class HeraldAdapter {
|
||||||
abstract public function getAdapterApplicationClass();
|
abstract public function getAdapterApplicationClass();
|
||||||
abstract public function getObject();
|
abstract public function getObject();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new characteristic object for this adapter.
|
||||||
|
*
|
||||||
|
* The adapter will use this object to test for interfaces, generate
|
||||||
|
* transactions, and interact with custom fields.
|
||||||
|
*
|
||||||
|
* Adapters must return an object from this method to enable custom
|
||||||
|
* field rules and various implicit actions.
|
||||||
|
*
|
||||||
|
* Normally, you'll return an empty version of the adapted object:
|
||||||
|
*
|
||||||
|
* return new ApplicationObject();
|
||||||
|
*
|
||||||
|
* @return null|object Template object.
|
||||||
|
*/
|
||||||
|
protected function newObject() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function supportsRuleType($rule_type) {
|
public function supportsRuleType($rule_type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -771,7 +789,19 @@ abstract class HeraldAdapter {
|
||||||
|
|
||||||
public function getActions($rule_type) {
|
public function getActions($rule_type) {
|
||||||
$custom_actions = $this->getCustomActionsForRuleType($rule_type);
|
$custom_actions = $this->getCustomActionsForRuleType($rule_type);
|
||||||
return mpull($custom_actions, 'getActionKey');
|
$custom_actions = mpull($custom_actions, 'getActionKey');
|
||||||
|
|
||||||
|
$actions = $custom_actions;
|
||||||
|
|
||||||
|
$object = $this->newObject();
|
||||||
|
|
||||||
|
if (($object instanceof PhabricatorProjectInterface)) {
|
||||||
|
if ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) {
|
||||||
|
$actions[] = self::ACTION_ADD_PROJECTS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActionNameMap($rule_type) {
|
public function getActionNameMap($rule_type) {
|
||||||
|
@ -1291,27 +1321,6 @@ abstract class HeraldAdapter {
|
||||||
/* -( Custom Field Integration )------------------------------------------- */
|
/* -( Custom Field Integration )------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an object which custom fields can be generated from while editing
|
|
||||||
* rules. Adapters must return an object from this method to enable custom
|
|
||||||
* field rules.
|
|
||||||
*
|
|
||||||
* Normally, you'll return an empty version of the adapted object, assuming
|
|
||||||
* it implements @{interface:PhabricatorCustomFieldInterface}:
|
|
||||||
*
|
|
||||||
* return new ApplicationObject();
|
|
||||||
*
|
|
||||||
* This is normally the only adapter method you need to override to enable
|
|
||||||
* Herald rules to run against custom fields.
|
|
||||||
*
|
|
||||||
* @return null|PhabricatorCustomFieldInterface Template object.
|
|
||||||
* @task customfield
|
|
||||||
*/
|
|
||||||
protected function getCustomFieldTemplateObject() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the prefix used to namespace Herald fields which are based on
|
* Returns the prefix used to namespace Herald fields which are based on
|
||||||
* custom fields.
|
* custom fields.
|
||||||
|
@ -1363,8 +1372,8 @@ abstract class HeraldAdapter {
|
||||||
$this->customFields = null;
|
$this->customFields = null;
|
||||||
|
|
||||||
|
|
||||||
$template_object = $this->getCustomFieldTemplateObject();
|
$template_object = $this->newObject();
|
||||||
if ($template_object) {
|
if ($template_object instanceof PhabricatorCustomFieldInterface) {
|
||||||
$object = $this->getObject();
|
$object = $this->getObject();
|
||||||
if (!$object) {
|
if (!$object) {
|
||||||
$object = $template_object;
|
$object = $template_object;
|
||||||
|
|
|
@ -26,6 +26,10 @@ final class HeraldCommitAdapter extends HeraldAdapter {
|
||||||
return 'PhabricatorDiffusionApplication';
|
return 'PhabricatorDiffusionApplication';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newObject() {
|
||||||
|
return new PhabricatorRepositoryCommit();
|
||||||
|
}
|
||||||
|
|
||||||
public function getObject() {
|
public function getObject() {
|
||||||
return $this->commit;
|
return $this->commit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,10 @@ final class HeraldDifferentialRevisionAdapter
|
||||||
return 'PhabricatorDifferentialApplication';
|
return 'PhabricatorDifferentialApplication';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newObject() {
|
||||||
|
return new DifferentialRevision();
|
||||||
|
}
|
||||||
|
|
||||||
public function getObject() {
|
public function getObject() {
|
||||||
return $this->revision;
|
return $this->revision;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,10 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
||||||
private $ccPHIDs = array();
|
private $ccPHIDs = array();
|
||||||
private $assignPHID;
|
private $assignPHID;
|
||||||
|
|
||||||
|
protected function newObject() {
|
||||||
|
return new ManiphestTask();
|
||||||
|
}
|
||||||
|
|
||||||
public function getAdapterApplicationClass() {
|
public function getAdapterApplicationClass() {
|
||||||
return 'PhabricatorManiphestApplication';
|
return 'PhabricatorManiphestApplication';
|
||||||
}
|
}
|
||||||
|
@ -90,7 +94,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
||||||
self::ACTION_ADD_CC,
|
self::ACTION_ADD_CC,
|
||||||
self::ACTION_EMAIL,
|
self::ACTION_EMAIL,
|
||||||
self::ACTION_ASSIGN_TASK,
|
self::ACTION_ASSIGN_TASK,
|
||||||
self::ACTION_ADD_PROJECTS,
|
|
||||||
self::ACTION_NOTHING,
|
self::ACTION_NOTHING,
|
||||||
),
|
),
|
||||||
parent::getActions($rule_type));
|
parent::getActions($rule_type));
|
||||||
|
@ -180,8 +183,4 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCustomFieldTemplateObject() {
|
|
||||||
return new ManiphestTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,10 @@ final class HeraldPholioMockAdapter extends HeraldAdapter {
|
||||||
return pht('React to mocks being created or updated.');
|
return pht('React to mocks being created or updated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newObject() {
|
||||||
|
return new PholioMock();
|
||||||
|
}
|
||||||
|
|
||||||
public function getObject() {
|
public function getObject() {
|
||||||
return $this->mock;
|
return $this->mock;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,10 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
|
||||||
return pht('React to wiki documents being created or updated.');
|
return pht('React to wiki documents being created or updated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newObject() {
|
||||||
|
return new PhrictionDocument();
|
||||||
|
}
|
||||||
|
|
||||||
public function getObject() {
|
public function getObject() {
|
||||||
return $this->document;
|
return $this->document;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue