1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30:56 +01:00

Give Herald rules a standard "Hnnn" object name

Summary: Allow Herald rules to be referred to with `H123`, etc., like other object types are. Herald rules now have proper PHIDs and an increasingly prominent role in triggering application actions. Although I suspect users will rarely use `H123` in Remarkup to mention rules, this can simplify some of the interfaces which relate objects across systems.

Test Plan: Looked at various interfaces and saw `H123` names. Mentioned `H123` in remarkup.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7786
This commit is contained in:
epriestley 2013-12-18 12:00:18 -08:00
parent 5863f792a6
commit 1ff3ef382d
8 changed files with 68 additions and 10 deletions

View file

@ -758,6 +758,7 @@ phutil_register_library_map(array(
'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php',
'HeraldPreCommitRefAdapter' => 'applications/diffusion/herald/HeraldPreCommitRefAdapter.php',
'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php',
'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php',
'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
'HeraldRule' => 'applications/herald/storage/HeraldRule.php',
'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php',
@ -3181,6 +3182,7 @@ phutil_register_library_map(array(
'HeraldPholioMockAdapter' => 'HeraldAdapter',
'HeraldPreCommitRefAdapter' => 'HeraldAdapter',
'HeraldRecursiveConditionsException' => 'Exception',
'HeraldRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'HeraldRule' =>
array(
0 => 'HeraldDAO',

View file

@ -30,6 +30,12 @@ final class PhabricatorApplicationHerald extends PhabricatorApplication {
return self::GROUP_ORGANIZATION;
}
public function getRemarkupRules() {
return array(
new HeraldRemarkupRule(),
);
}
public function getRoutes() {
return array(
'/herald/' => array(

View file

@ -41,7 +41,7 @@ final class HeraldRuleListController extends HeraldController
$id = $rule->getID();
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Rule %s', $rule->getID()))
->setObjectName("H{$id}")
->setHeader($rule->getName())
->setHref($this->getApplicationURI("rule/{$id}/"));

View file

@ -41,10 +41,12 @@ final class HeraldRuleViewController extends HeraldController {
$actions = $this->buildActionView($rule);
$properties = $this->buildPropertyView($rule, $actions);
$id = $rule->getID();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Rule %d', $rule->getID())));
->setName("H{$id}"));
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)

View file

@ -368,7 +368,9 @@ final class HeraldEngine {
$name = $rule->getName();
$id = $rule->getID();
$effect->setReason(
'Conditions were met for Herald rule "'.$name.'" (#'.$id.').');
pht(
'Conditions were met for %s',
"H{$id} {$name}"));
$effects[] = $effect;
}

View file

@ -35,9 +35,39 @@ final class HeraldPHIDTypeRule extends PhabricatorPHIDType {
$id = $rule->getID();
$name = $rule->getName();
$handle->setName($name);
$handle->setName("H{$id}");
$handle->setFullName("H{$id} {$name}");
$handle->setURI("/herald/rule/{$id}/");
}
}
public function canLoadNamedObject($name) {
return preg_match('/^H\d*[1-9]\d*$/i', $name);
}
public function loadNamedObjects(
PhabricatorObjectQuery $query,
array $names) {
$id_map = array();
foreach ($names as $name) {
$id = (int)substr($name, 1);
$id_map[$id][] = $name;
}
$objects = id(new HeraldRuleQuery())
->setViewer($query->getViewer())
->withIDs(array_keys($id_map))
->execute();
$results = array();
foreach ($objects as $id => $object) {
foreach (idx($id_map, $id, array()) as $name) {
$results[$name] = $object;
}
}
return $results;
}
}

View file

@ -0,0 +1,18 @@
<?php
final class HeraldRemarkupRule
extends PhabricatorRemarkupRuleObject {
protected function getObjectNamePrefix() {
return 'H';
}
protected function loadObjects(array $ids) {
$viewer = $this->getEngine()->getConfig('viewer');
return id(new HeraldRuleQuery())
->setViewer($viewer)
->withIDs($ids)
->execute();
}
}

View file

@ -232,14 +232,12 @@ final class PhabricatorRepositoryCommitHeraldWorker
}
if ($status == PhabricatorAuditStatusConstants::AUDIT_REQUIRED) {
$reasons[] = pht(
'Herald Rule #%d "%s" Triggered Audit',
$id,
$rule_name);
'%s Triggered Audit',
"H{$id} {$rule_name}");
} else {
$reasons[] = pht(
'Herald Rule #%d "%s" Triggered CC',
$id,
$rule_name);
'%s Triggered CC',
"H{$id} {$rule_name}");
}
}