Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php
12256 views
1
<?php
2
3
final class HarbormasterRunBuildPlansHeraldAction
4
extends HeraldAction {
5
6
const DO_BUILD = 'do.build';
7
8
const ACTIONCONST = 'harbormaster.build';
9
10
public function getRequiredAdapterStates() {
11
return array(
12
HeraldBuildableState::STATECONST,
13
);
14
}
15
16
public function getActionGroupKey() {
17
return HeraldSupportActionGroup::ACTIONGROUPKEY;
18
}
19
20
public function supportsObject($object) {
21
$adapter = $this->getAdapter();
22
return ($adapter instanceof HarbormasterBuildableAdapterInterface);
23
}
24
25
protected function applyBuilds(array $phids, HeraldRule $rule) {
26
$adapter = $this->getAdapter();
27
28
$allowed_types = array(
29
HarbormasterBuildPlanPHIDType::TYPECONST,
30
);
31
32
$targets = $this->loadStandardTargets($phids, $allowed_types, array());
33
if (!$targets) {
34
return;
35
}
36
37
$phids = array_fuse(array_keys($targets));
38
39
foreach ($phids as $phid) {
40
$request = id(new HarbormasterBuildRequest())
41
->setBuildPlanPHID($phid)
42
->setInitiatorPHID($rule->getPHID());
43
$adapter->queueHarbormasterBuildRequest($request);
44
}
45
46
$this->logEffect(self::DO_BUILD, $phids);
47
}
48
49
protected function getActionEffectMap() {
50
return array(
51
self::DO_BUILD => array(
52
'icon' => 'fa-play',
53
'color' => 'green',
54
'name' => pht('Building'),
55
),
56
);
57
}
58
59
protected function renderActionEffectDescription($type, $data) {
60
switch ($type) {
61
case self::DO_BUILD:
62
return pht(
63
'Started %s build(s): %s.',
64
phutil_count($data),
65
$this->renderHandleList($data));
66
}
67
}
68
69
public function getHeraldActionName() {
70
return pht('Run build plans');
71
}
72
73
public function supportsRuleType($rule_type) {
74
return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
75
}
76
77
public function applyEffect($object, HeraldEffect $effect) {
78
return $this->applyBuilds($effect->getTarget(), $effect->getRule());
79
}
80
81
public function getHeraldActionStandardType() {
82
return self::STANDARD_PHID_LIST;
83
}
84
85
protected function getDatasource() {
86
return new HarbormasterBuildPlanDatasource();
87
}
88
89
public function renderActionDescription($value) {
90
return pht(
91
'Run build plans: %s.',
92
$this->renderHandleList($value));
93
}
94
95
public function getPHIDsAffectedByAction(HeraldActionRecord $record) {
96
return $record->getTarget();
97
}
98
99
public function isActionAvailable() {
100
return id(new PhabricatorHarbormasterApplication())->isInstalled();
101
}
102
103
}
104
105