1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 05:20:56 +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:
epriestley 2015-04-22 14:01:32 -07:00
parent 501630d931
commit 959e9d9ac2
6 changed files with 56 additions and 32 deletions

View file

@ -244,7 +244,7 @@ abstract class HeraldAdapter {
}
protected function newTransaction() {
$object = $this->getObject();
$object = $this->newObject();
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
throw new Exception(
@ -258,8 +258,6 @@ abstract class HeraldAdapter {
}
/**
* NOTE: You generally should not override this; it exists to support legacy
* adapters which had hard-coded content types.
@ -273,6 +271,26 @@ abstract class HeraldAdapter {
abstract public function getAdapterApplicationClass();
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) {
return false;
}
@ -771,7 +789,19 @@ abstract class HeraldAdapter {
public function getActions($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) {
@ -1291,27 +1321,6 @@ abstract class HeraldAdapter {
/* -( 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
* custom fields.
@ -1363,8 +1372,8 @@ abstract class HeraldAdapter {
$this->customFields = null;
$template_object = $this->getCustomFieldTemplateObject();
if ($template_object) {
$template_object = $this->newObject();
if ($template_object instanceof PhabricatorCustomFieldInterface) {
$object = $this->getObject();
if (!$object) {
$object = $template_object;

View file

@ -26,6 +26,10 @@ final class HeraldCommitAdapter extends HeraldAdapter {
return 'PhabricatorDiffusionApplication';
}
public function newObject() {
return new PhabricatorRepositoryCommit();
}
public function getObject() {
return $this->commit;
}

View file

@ -24,6 +24,10 @@ final class HeraldDifferentialRevisionAdapter
return 'PhabricatorDifferentialApplication';
}
public function newObject() {
return new DifferentialRevision();
}
public function getObject() {
return $this->revision;
}

View file

@ -6,6 +6,10 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
private $ccPHIDs = array();
private $assignPHID;
protected function newObject() {
return new ManiphestTask();
}
public function getAdapterApplicationClass() {
return 'PhabricatorManiphestApplication';
}
@ -90,7 +94,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
self::ACTION_ADD_CC,
self::ACTION_EMAIL,
self::ACTION_ASSIGN_TASK,
self::ACTION_ADD_PROJECTS,
self::ACTION_NOTHING,
),
parent::getActions($rule_type));
@ -180,8 +183,4 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
return $result;
}
protected function getCustomFieldTemplateObject() {
return new ManiphestTask();
}
}

View file

@ -13,6 +13,10 @@ final class HeraldPholioMockAdapter extends HeraldAdapter {
return pht('React to mocks being created or updated.');
}
public function newObject() {
return new PholioMock();
}
public function getObject() {
return $this->mock;
}

View file

@ -13,6 +13,10 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
return pht('React to wiki documents being created or updated.');
}
public function newObject() {
return new PhrictionDocument();
}
public function getObject() {
return $this->document;
}