Differential D9637 Diff 23125 src/applications/chronicle/action/ChronicleStartHarbormasterBuildAction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/chronicle/action/ChronicleStartHarbormasterBuildAction.php
- This file was added.
<?php | |||||
final class ChronicleStartHarbormasterBuildAction | |||||
extends ChronicleAction { | |||||
public function getName() { | |||||
return pht('Start Harbormaster Build'); | |||||
} | |||||
public function getDescription() { | |||||
return pht('Starts a Harbormaster build against a branch in a repository'); | |||||
} | |||||
public function execute(ChronicleTrigger $trigger) { | |||||
$callsign = $this->getSetting('callsign'); | |||||
$branch = $this->getSetting('branch'); | |||||
$plan_id = $this->getSetting('planid'); | |||||
// Get commit identifier. | |||||
$refs = id(new ConduitCall( | |||||
'diffusion.resolverefs', | |||||
array( | |||||
'refs' => array($branch), | |||||
'callsign' => $callsign | |||||
))) | |||||
->setUser(PhabricatorUser::getOmnipotentUser()) | |||||
->execute(); | |||||
$candidate_refs = $refs[$branch]; | |||||
$commit_ref = null; | |||||
foreach ($candidate_refs as $candidate_ref) { | |||||
if ($candidate_ref['type'] === 'commit') { | |||||
$commit_ref = $candidate_ref['identifier']; | |||||
} | |||||
} | |||||
if ($commit_ref === null) { | |||||
return; | |||||
} | |||||
$commit = id(new DiffusionCommitQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->withIdentifiers(array($commit_ref)) | |||||
->executeOne(); | |||||
if ($commit === null) { | |||||
return; | |||||
} | |||||
$build_plan = id(new HarbormasterBuildPlanQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->withIDs(array($plan_id)) | |||||
->executeOne(); | |||||
if ($build_plan === null) { | |||||
return; | |||||
} | |||||
$buildable = HarbormasterBuildable::createOrLoadExisting( | |||||
PhabricatorUser::getOmnipotentUser(), | |||||
$commit->getPHID(), | |||||
$commit->getRepository()->getPHID()); | |||||
$buildable->applyPlan($build_plan); | |||||
return; | |||||
} | |||||
public function getFieldSpecifications() { | |||||
return array( | |||||
'callsign' => array( | |||||
'name' => pht('Repository Callsign'), | |||||
'type' => 'text', | |||||
'required' => true, | |||||
), | |||||
'branch' => array( | |||||
'name' => pht('Branch or Reference'), | |||||
'type' => 'text', | |||||
'required' => true | |||||
), | |||||
'planid' => array( | |||||
'name' => pht('Build Plan ID'), | |||||
'type' => 'text', | |||||
'required' => true, | |||||
), | |||||
); | |||||
} | |||||
public function canCreateOrEdit(PhabricatorUser $viewer) { | |||||
return PhabricatorPolicyFilter::hasCapability( | |||||
$viewer, | |||||
new PhabricatorApplicationHarbormaster(), | |||||
HarbormasterCapabilityManagePlans::CAPABILITY); | |||||
} | |||||
} |