mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-12 00:26:13 +01:00
d60d4e6a05
Summary: Fixes T7961. Currently, we present Herald users with actions like "Require legalpad signatures" and "Run build plans" even if Legalpad and Harbormaster are not installed. Instead, allow fields and actions to be made "unavailable", which means that we won't present them as options when adding to new or existing rules. If you edit a rule which already uses one of these fields or actions, it isn't affected. Test Plan: - Created a rule with a legalpad action, uninstalled legalpad, edited the rule. Action remained untouched. - Created a new rule, wasn't offered the legalpad action. - Reinstalled the application, saw the action again. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T7961 Differential Revision: https://secure.phabricator.com/D20808
103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
|
|
final class HarbormasterRunBuildPlansHeraldAction
|
|
extends HeraldAction {
|
|
|
|
const DO_BUILD = 'do.build';
|
|
|
|
const ACTIONCONST = 'harbormaster.build';
|
|
|
|
public function getRequiredAdapterStates() {
|
|
return array(
|
|
HeraldBuildableState::STATECONST,
|
|
);
|
|
}
|
|
|
|
public function getActionGroupKey() {
|
|
return HeraldSupportActionGroup::ACTIONGROUPKEY;
|
|
}
|
|
|
|
public function supportsObject($object) {
|
|
$adapter = $this->getAdapter();
|
|
return ($adapter instanceof HarbormasterBuildableAdapterInterface);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
protected function getActionEffectMap() {
|
|
return array(
|
|
self::DO_BUILD => array(
|
|
'icon' => 'fa-play',
|
|
'color' => 'green',
|
|
'name' => pht('Building'),
|
|
),
|
|
);
|
|
}
|
|
|
|
protected function renderActionEffectDescription($type, $data) {
|
|
switch ($type) {
|
|
case self::DO_BUILD:
|
|
return pht(
|
|
'Started %s build(s): %s.',
|
|
phutil_count($data),
|
|
$this->renderHandleList($data));
|
|
}
|
|
}
|
|
|
|
public function getHeraldActionName() {
|
|
return pht('Run build plans');
|
|
}
|
|
|
|
public function supportsRuleType($rule_type) {
|
|
return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
|
|
}
|
|
|
|
public function applyEffect($object, HeraldEffect $effect) {
|
|
return $this->applyBuilds($effect->getTarget(), $effect->getRule());
|
|
}
|
|
|
|
public function getHeraldActionStandardType() {
|
|
return self::STANDARD_PHID_LIST;
|
|
}
|
|
|
|
protected function getDatasource() {
|
|
return new HarbormasterBuildPlanDatasource();
|
|
}
|
|
|
|
public function renderActionDescription($value) {
|
|
return pht(
|
|
'Run build plans: %s.',
|
|
$this->renderHandleList($value));
|
|
}
|
|
|
|
public function getPHIDsAffectedByAction(HeraldActionRecord $record) {
|
|
return $record->getTarget();
|
|
}
|
|
|
|
public function isActionAvailable() {
|
|
return id(new PhabricatorHarbormasterApplication())->isInstalled();
|
|
}
|
|
|
|
}
|