1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Integrate Pholio with Herald

Summary: Ref T2766. Does the integration via ApplicationTransactionsEditor. Only did addCC and Flag for proof of concept.

Test Plan: Made a rule to cc, made a rule to flag. They worked!  (will attach screens to diff)

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T2766

Differential Revision: https://secure.phabricator.com/D6766
This commit is contained in:
Bob Trahan 2013-08-15 13:10:45 -07:00
parent fde0d1f1d6
commit f909a295f7
7 changed files with 211 additions and 0 deletions

View file

@ -613,6 +613,7 @@ phutil_register_library_map(array(
'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php',
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php',
'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php',
'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php',
'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php',
'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
'HeraldRule' => 'applications/herald/storage/HeraldRule.php',
@ -2627,6 +2628,7 @@ phutil_register_library_map(array(
'HeraldInvalidFieldException' => 'Exception',
'HeraldNewController' => 'HeraldController',
'HeraldPHIDTypeRule' => 'PhabricatorPHIDType',
'HeraldPholioMockAdapter' => 'HeraldAdapter',
'HeraldRecursiveConditionsException' => 'Exception',
'HeraldRule' =>
array(

View file

@ -1,5 +1,8 @@
<?php
/**
* @group herald
*/
abstract class HeraldAdapter {
const FIELD_TITLE = 'title';

View file

@ -1,5 +1,8 @@
<?php
/**
* @group herald
*/
final class HeraldCommitAdapter extends HeraldAdapter {
const FIELD_NEED_AUDIT_FOR_PACKAGE = 'need-audit-for-package';

View file

@ -1,5 +1,8 @@
<?php
/**
* @group herald
*/
final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
protected $revision;

View file

@ -0,0 +1,115 @@
<?php
/**
* @group herald
*/
final class HeraldPholioMockAdapter extends HeraldAdapter {
private $mock;
private $ccPHIDs = array();
public function setMock(PholioMock $mock) {
$this->mock = $mock;
return $this;
}
public function getMock() {
return $this->mock;
}
private function setCcPHIDs(array $cc_phids) {
$this->ccPHIDs = $cc_phids;
return $this;
}
public function getCcPHIDs() {
return $this->ccPHIDs;
}
public function getAdapterContentName() {
return pht('Pholio Mocks');
}
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->getMock()->getPHID();
}
public function getHeraldName() {
return 'M'.$this->getMock()->getID();
}
public function getHeraldField($field) {
switch ($field) {
case self::FIELD_TITLE:
return $this->getMock()->getName();
case self::FIELD_BODY:
return $this->getMock()->getDescription();
case self::FIELD_AUTHOR:
return $this->getMock()->getAuthorPHID();
case self::FIELD_CC:
return PhabricatorSubscribersQuery::loadSubscribersForPHID(
$this->getMock()->getPHID());
}
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->getMock()->getPHID());
break;
default:
throw new Exception("No rules to handle action '{$action}'.");
}
}
return $result;
}
}

View file

@ -383,6 +383,33 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
return true;
}
protected function supportsHerald() {
return true;
}
protected function buildHeraldAdapter(
PhabricatorLiskDAO $object,
array $xactions) {
return id(new HeraldPholioMockAdapter())
->setMock($object);
}
protected function didApplyHeraldRules(
PhabricatorLiskDAO $object,
HeraldAdapter $adapter,
HeraldTranscript $transcript) {
$cc_phids = $adapter->getCcPHIDs();
if ($cc_phids) {
id(new PhabricatorSubscriptionsEditor())
->setObject($object)
->setActor($this->requireActor())
->subscribeImplicit($cc_phids)
->save();
}
}
protected function sortTransactions(array $xactions) {
$head = array();
$tail = array();

View file

@ -16,6 +16,8 @@ abstract class PhabricatorApplicationTransactionEditor
private $mentionedPHIDs;
private $continueOnNoEffect;
private $parentMessageID;
private $heraldAdapter;
private $heraldTranscript;
private $subscribers;
private $isPreview;
@ -439,6 +441,10 @@ abstract class PhabricatorApplicationTransactionEditor
$this->applyExternalEffects($object, $xaction);
}
if ($this->supportsHerald()) {
$this->applyHeraldRules($object, $xactions);
}
$this->applyFinalEffects($object, $xactions);
if ($read_locking) {
@ -1324,6 +1330,58 @@ abstract class PhabricatorApplicationTransactionEditor
}
/* -( Herald Integration )-------------------------------------------------- */
protected function supportsHerald() {
return false;
}
protected function buildHeraldAdapter(
PhabricatorLiskDAO $object,
array $xactions) {
throw new Exception('No herald adapter specified.');
}
private function setHeraldAdapter(HeraldAdapter $adapter) {
$this->heraldAdapter = $adapter;
return $this;
}
protected function getHeraldAdapter() {
return $this->heraldAdapter;
}
private function setHeraldTranscript(HeraldTranscript $transcript) {
$this->heraldTranscript = $transcript;
return $this;
}
protected function getHeraldTranscript() {
return $this->heraldTranscript;
}
private function applyHeraldRules(
PhabricatorLiskDAO $object,
array $xactions) {
$adapter = $this->buildHeraldAdapter($object, $xactions);
$xscript = HeraldEngine::loadAndApplyRules($adapter);
$this->setHeraldAdapter($adapter);
$this->setHeraldTranscript($xscript);
$this->didApplyHeraldRules($object, $adapter, $xscript);
}
protected function didApplyHeraldRules(
PhabricatorLiskDAO $object,
HeraldAdapter $adapter,
HeraldTranscript $transcript) {
}
/* -( Custom Fields )------------------------------------------------------ */