Page MenuHomePhabricator
Paste P1860

CustomDifferentialRunPackageBuildsHeraldAction.php
ActivePublic

Authored by epriestley on Sep 28 2015, 7:03 PM.
Tags
None
Referenced Files
F858901: CustomDifferentialRunPackageBuildsHeraldAction.php
Oct 2 2015, 12:31 PM
F846665: CustomDifferentialRunPackageBuildsHeraldAction.php
Sep 28 2015, 7:03 PM
Subscribers
None
<?php
final class CustomDifferentialRunPackageBuildsHeraldAction
extends HeraldAction {
const ACTIONCONST = 'custom.differential.run-package-builds';
const DO_BUILD = 'do.custom-package-build';
public function getHeraldActionName() {
return pht('Run builds for affected packages');
}
public function getActionGroupKey() {
return HeraldApplicationActionGroup::ACTIONGROUPKEY;
}
public function supportsObject($object) {
return ($object instanceof DifferentialRevision);
}
public function supportsRuleType($rule_type) {
return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL);
}
public function applyEffect($object, HeraldEffect $effect) {
$viewer = PhabricatorUser::getOmnipotentUser();
// Replace this with the full field key of the custom field you want to
// examine. Generally, "std:owners:" plus whatever you named the field.
$field_key = "std:owners:mycompany:lore";
// Replace this with the PHID of the build plan you want to execute.
$buildplan_phid = "PHID-HMCP-vadfbuqvdbx5gy65pfba";
$adapter = $this->getAdapter();
$packages = $adapter->loadAffectedPackages();
$package_phids = mpull($packages, 'getPHID');
$this->logEffect(self::DO_BUILD, $package_phids);
$all = array();
foreach ($packages as $package) {
$field_list = PhabricatorCustomField::getObjectFields(
$package,
PhabricatorCustomField::ROLE_VIEW);
$field_list
->setViewer($viewer)
->readFieldsFromStorage($package);
foreach ($field_list->getFields() as $field) {
$key = $field->getFieldKey();
if ($key == $field_key) {
$all[] = $field->getValueForStorage();
}
}
}
$all = implode("\n", $all);
$all = phutil_split_lines($all, false);
$all = array_filter($all);
$all = array_unique($all);
if (!$all) {
return;
}
foreach ($all as $parameter) {
$request = id(new HarbormasterBuildRequest())
->setBuildPlanPHID($buildplan_phid)
->setBuildParameters(
array(
'build-name-from-owners' => $parameter,
));
$adapter->queueHarbormasterBuildRequest($request);
}
}
public function getHeraldActionStandardType() {
return self::STANDARD_NONE;
}
public function renderActionDescription($value) {
return pht('Run builds for affected pakages.');
}
protected function getActionEffectMap() {
return array(
self::DO_BUILD => array(
'icon' => 'fa-play',
'color' => 'green',
'name' => pht('Ran Builds'),
),
);
}
protected function renderActionEffectDescription($type, $data) {
switch ($type) {
case self::DO_BUILD:
if (!$data) {
return pht('No affected packages.');
} else {
return pht(
'Ran builds for affected packages: %s.',
$this->renderHandleList($data));
}
}
}
}