Path: blob/master/src/applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php
12256 views
<?php12final class HarbormasterWaitForPreviousBuildStepImplementation3extends HarbormasterBuildStepImplementation {45public function getName() {6return pht('Wait for Previous Commits to Build');7}89public function getGenericDescription() {10return pht(11'Wait for previous commits to finish building the current plan '.12'before continuing.');13}1415public function getBuildStepGroupKey() {16return HarbormasterControlBuildStepGroup::GROUPKEY;17}1819public function execute(20HarbormasterBuild $build,21HarbormasterBuildTarget $build_target) {2223// We can only wait when building against commits.24$buildable = $build->getBuildable();25$object = $buildable->getBuildableObject();26if (!($object instanceof PhabricatorRepositoryCommit)) {27return;28}2930// Block until all previous builds of the same build plan have31// finished.32$plan = $build->getBuildPlan();33$blockers = $this->getBlockers($object, $plan, $build);3435if ($blockers) {36throw new PhabricatorWorkerYieldException(15);37}38}3940private function getBlockers(41PhabricatorRepositoryCommit $commit,42HarbormasterBuildPlan $plan,43HarbormasterBuild $source) {4445$call = new ConduitCall(46'diffusion.commitparentsquery',47array(48'commit' => $commit->getCommitIdentifier(),49'repository' => $commit->getRepository()->getPHID(),50));51$call->setUser(PhabricatorUser::getOmnipotentUser());52$parents = $call->execute();5354$parents = id(new DiffusionCommitQuery())55->setViewer(PhabricatorUser::getOmnipotentUser())56->withRepository($commit->getRepository())57->withIdentifiers($parents)58->execute();5960$blockers = array();6162$build_objects = array();63foreach ($parents as $parent) {64if (!$parent->isImported()) {65$blockers[] = pht('Commit %s', $parent->getCommitIdentifier());66} else {67$build_objects[] = $parent->getPHID();68}69}7071if ($build_objects) {72$buildables = id(new HarbormasterBuildableQuery())73->setViewer(PhabricatorUser::getOmnipotentUser())74->withBuildablePHIDs($build_objects)75->withManualBuildables(false)76->execute();77$buildable_phids = mpull($buildables, 'getPHID');7879if ($buildable_phids) {80$builds = id(new HarbormasterBuildQuery())81->setViewer(PhabricatorUser::getOmnipotentUser())82->withBuildablePHIDs($buildable_phids)83->withBuildPlanPHIDs(array($plan->getPHID()))84->execute();8586foreach ($builds as $build) {87if (!$build->isComplete()) {88$blockers[] = pht('Build %d', $build->getID());89}90}91}92}9394return $blockers;95}9697}9899100