mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 07:11:04 +01:00
Add herald support for Maniphest
Summary: standing on the shoulders of the badass work to move Maniphest to ApplicationTransactions, this diff implements a few methods and adds an adapter class. For now, we can add cc and flag tasks. I figure see what people ask for? Ref T1368. Test Plan: created herald rules for title and description text hits. made tasks and verified CC and flags worked. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Maniphest Tasks: T1368, T1638 Differential Revision: https://secure.phabricator.com/D7122
This commit is contained in:
parent
9be7a948f9
commit
660f1f3e64
3 changed files with 142 additions and 0 deletions
|
@ -629,6 +629,7 @@ phutil_register_library_map(array(
|
||||||
'HeraldInvalidActionException' => 'applications/herald/engine/exception/HeraldInvalidActionException.php',
|
'HeraldInvalidActionException' => 'applications/herald/engine/exception/HeraldInvalidActionException.php',
|
||||||
'HeraldInvalidConditionException' => 'applications/herald/engine/exception/HeraldInvalidConditionException.php',
|
'HeraldInvalidConditionException' => 'applications/herald/engine/exception/HeraldInvalidConditionException.php',
|
||||||
'HeraldInvalidFieldException' => 'applications/herald/engine/exception/HeraldInvalidFieldException.php',
|
'HeraldInvalidFieldException' => 'applications/herald/engine/exception/HeraldInvalidFieldException.php',
|
||||||
|
'HeraldManiphestTaskAdapter' => 'applications/herald/adapter/HeraldManiphestTaskAdapter.php',
|
||||||
'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php',
|
'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php',
|
||||||
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php',
|
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php',
|
||||||
'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php',
|
'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php',
|
||||||
|
@ -2692,6 +2693,7 @@ phutil_register_library_map(array(
|
||||||
'HeraldInvalidActionException' => 'Exception',
|
'HeraldInvalidActionException' => 'Exception',
|
||||||
'HeraldInvalidConditionException' => 'Exception',
|
'HeraldInvalidConditionException' => 'Exception',
|
||||||
'HeraldInvalidFieldException' => 'Exception',
|
'HeraldInvalidFieldException' => 'Exception',
|
||||||
|
'HeraldManiphestTaskAdapter' => 'HeraldAdapter',
|
||||||
'HeraldNewController' => 'HeraldController',
|
'HeraldNewController' => 'HeraldController',
|
||||||
'HeraldPHIDTypeRule' => 'PhabricatorPHIDType',
|
'HeraldPHIDTypeRule' => 'PhabricatorPHIDType',
|
||||||
'HeraldPholioMockAdapter' => 'HeraldAdapter',
|
'HeraldPholioMockAdapter' => 'HeraldAdapter',
|
||||||
|
|
114
src/applications/herald/adapter/HeraldManiphestTaskAdapter.php
Normal file
114
src/applications/herald/adapter/HeraldManiphestTaskAdapter.php
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group herald
|
||||||
|
*/
|
||||||
|
final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
||||||
|
|
||||||
|
private $task;
|
||||||
|
private $ccPHIDs = array();
|
||||||
|
|
||||||
|
public function setTask(ManiphestTask $task) {
|
||||||
|
$this->task = $task;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getTask() {
|
||||||
|
return $this->task;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setCcPHIDs(array $cc_phids) {
|
||||||
|
$this->ccPHIDs = $cc_phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getCcPHIDs() {
|
||||||
|
return $this->ccPHIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdapterContentName() {
|
||||||
|
return pht('Maniphest Tasks');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFields() {
|
||||||
|
return array(
|
||||||
|
self::FIELD_TITLE,
|
||||||
|
self::FIELD_BODY,
|
||||||
|
self::FIELD_AUTHOR,
|
||||||
|
self::FIELD_CC,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActions($rule_type) {
|
||||||
|
switch ($rule_type) {
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
||||||
|
return array(
|
||||||
|
self::ACTION_ADD_CC,
|
||||||
|
self::ACTION_NOTHING,
|
||||||
|
);
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
||||||
|
return array(
|
||||||
|
self::ACTION_ADD_CC,
|
||||||
|
self::ACTION_FLAG,
|
||||||
|
self::ACTION_NOTHING,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPHID() {
|
||||||
|
return $this->getTask()->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeraldName() {
|
||||||
|
return 'T'.$this->getTask()->getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeraldField($field) {
|
||||||
|
switch ($field) {
|
||||||
|
case self::FIELD_TITLE:
|
||||||
|
return $this->getTask()->getTitle();
|
||||||
|
case self::FIELD_BODY:
|
||||||
|
return $this->getTask()->getDescription();
|
||||||
|
case self::FIELD_AUTHOR:
|
||||||
|
return $this->getTask()->getAuthorPHID();
|
||||||
|
case self::FIELD_CC:
|
||||||
|
return $this->getTask()->getCCPHIDs();
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getHeraldField($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyHeraldEffects(array $effects) {
|
||||||
|
assert_instances_of($effects, 'HeraldEffect');
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
foreach ($effects as $effect) {
|
||||||
|
$action = $effect->getAction();
|
||||||
|
switch ($action) {
|
||||||
|
case self::ACTION_NOTHING:
|
||||||
|
$result[] = new HeraldApplyTranscript(
|
||||||
|
$effect,
|
||||||
|
true,
|
||||||
|
pht('Great success at doing nothing.'));
|
||||||
|
break;
|
||||||
|
case self::ACTION_ADD_CC:
|
||||||
|
$add_cc = array();
|
||||||
|
foreach ($effect->getTarget() as $phid) {
|
||||||
|
$add_cc[$phid] = true;
|
||||||
|
}
|
||||||
|
$this->setCcPHIDs(array_keys($add_cc));
|
||||||
|
$result[] = new HeraldApplyTranscript(
|
||||||
|
$effect,
|
||||||
|
true,
|
||||||
|
pht('Added address to cc list.'));
|
||||||
|
break;
|
||||||
|
case self::ACTION_FLAG:
|
||||||
|
$result[] = parent::applyFlagEffect(
|
||||||
|
$effect,
|
||||||
|
$this->getTask()->getPHID());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("No rules to handle action '{$action}'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -189,4 +189,30 @@ final class ManiphestTransactionEditorPro
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function supportsHerald() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildHeraldAdapter(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
array $xactions) {
|
||||||
|
|
||||||
|
return id(new HeraldManiphestTaskAdapter())
|
||||||
|
->setTask($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function didApplyHeraldRules(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
HeraldAdapter $adapter,
|
||||||
|
HeraldTranscript $transcript) {
|
||||||
|
|
||||||
|
$cc_phids = $adapter->getCcPHIDs();
|
||||||
|
if ($cc_phids) {
|
||||||
|
$existing_cc = $object->getCCPHIDs();
|
||||||
|
$new_cc = array_unique(array_merge($cc_phids, $existing_cc));
|
||||||
|
$object->setCCPHIDs($new_cc);
|
||||||
|
$object->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue