private function buildTimeline(HeraldRule $rule)
 {
     $viewer = $this->getRequest()->getUser();
     $xactions = id(new HeraldTransactionQuery())->setViewer($viewer)->withObjectPHIDs(array($rule->getPHID()))->needComments(true)->execute();
     $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer);
     foreach ($xactions as $xaction) {
         if ($xaction->getComment()) {
             $engine->addObject($xaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
         }
     }
     $engine->process();
     return id(new PhabricatorApplicationTransactionView())->setUser($viewer)->setObjectPHID($rule->getPHID())->setTransactions($xactions)->setMarkupEngine($engine);
 }
 protected function applyRouting(HeraldRule $rule, $route, $phids)
 {
     $adapter = $this->getAdapter();
     $mail = $adapter->getObject();
     $mail->addRoutingRule($route, $phids, $rule->getPHID());
     $this->logEffect(self::DO_ROUTE, array('route' => $route, 'phids' => $phids));
 }
 protected function applyBuilds(array $phids, HeraldRule $rule)
 {
     $adapter = $this->getAdapter();
     $allowed_types = array(HarbormasterBuildPlanPHIDType::TYPECONST);
     $targets = $this->loadStandardTargets($phids, $allowed_types, array());
     if (!$targets) {
         return;
     }
     $phids = array_fuse(array_keys($targets));
     foreach ($phids as $phid) {
         $request = id(new HarbormasterBuildRequest())->setBuildPlanPHID($phid)->setInitiatorPHID($rule->getPHID());
         $adapter->queueHarbormasterBuildRequest($request);
     }
     $this->logEffect(self::DO_BUILD, $phids);
 }
예제 #4
0
 protected function getRuleEffects(HeraldRule $rule, HeraldAdapter $object)
 {
     $effects = array();
     foreach ($rule->getActions() as $action) {
         $effect = new HeraldEffect();
         $effect->setObjectPHID($object->getPHID());
         $effect->setAction($action->getAction());
         $effect->setTarget($action->getTarget());
         $effect->setRuleID($rule->getID());
         $effect->setRulePHID($rule->getPHID());
         $name = $rule->getName();
         $id = $rule->getID();
         $effect->setReason(pht('Conditions were met for %s', "H{$id} {$name}"));
         $effects[] = $effect;
     }
     return $effects;
 }
예제 #5
0
 public function doesRuleMatch(HeraldRule $rule, HeraldAdapter $object)
 {
     $phid = $rule->getPHID();
     if (isset($this->results[$phid])) {
         // If we've already evaluated this rule because another rule depends
         // on it, we don't need to reevaluate it.
         return $this->results[$phid];
     }
     if (isset($this->stack[$phid])) {
         // 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_phid => $ignored) {
             $this->results[$rule_phid] = false;
         }
         throw new HeraldRecursiveConditionsException();
     }
     $this->stack[$phid] = true;
     $all = $rule->getMustMatchAll();
     $conditions = $rule->getConditions();
     $result = null;
     $local_version = id(new HeraldRule())->getConfigVersion();
     if ($rule->getConfigVersion() > $local_version) {
         $reason = pht('Rule could not be processed, it was created with a newer version ' . 'of Herald.');
         $result = false;
     } else {
         if (!$conditions) {
             $reason = pht('Rule failed automatically because it has no conditions.');
             $result = false;
         } else {
             if (!$rule->hasValidAuthor()) {
                 $reason = pht('Rule failed automatically because its owner is invalid ' . 'or disabled.');
                 $result = false;
             } else {
                 if (!$this->canAuthorViewObject($rule, $object)) {
                     $reason = pht('Rule failed automatically because it is a personal rule and its ' . 'owner can not see the object.');
                     $result = false;
                 } else {
                     if (!$this->canRuleApplyToObject($rule, $object)) {
                         $reason = pht('Rule failed automatically because it is an object rule which is ' . 'not relevant for this object.');
                         $result = false;
                     } else {
                         foreach ($conditions as $condition) {
                             try {
                                 $object->getHeraldField($condition->getFieldName());
                             } catch (Exception $ex) {
                                 $reason = pht('Field "%s" does not exist!', $condition->getFieldName());
                                 $result = false;
                                 break;
                             }
                             $match = $this->doesConditionMatch($rule, $condition, $object);
                             if (!$all && $match) {
                                 $reason = pht('Any condition matched.');
                                 $result = true;
                                 break;
                             }
                             if ($all && !$match) {
                                 $reason = pht('Not all conditions matched.');
                                 $result = false;
                                 break;
                             }
                         }
                         if ($result === null) {
                             if ($all) {
                                 $reason = pht('All conditions matched.');
                                 $result = true;
                             } else {
                                 $reason = pht('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->getAuthorPHID());
     $this->transcript->addRuleTranscript($rule_transcript);
     return $result;
 }