mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-27 06:58:17 +01:00
add initiator.phid parameter to HM builds
Summary: Fix T9662. Record who initiated the build, and allow this information as a parameter. In this implementation, a 're-run' keeps the original initiator, which we maybe not desired? Test Plan: Make a HTTP step with initiator.phid, trigger manually, via HM, via ./bin/harbormaster build. Look at requests made. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T9662 Differential Revision: https://secure.phabricator.com/D14380
This commit is contained in:
parent
5c6d2be18f
commit
1898864b6c
8 changed files with 44 additions and 9 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_build
|
||||||
|
ADD COLUMN initiatorPHID VARBINARY(64);
|
|
@ -59,7 +59,7 @@ final class HarbormasterPlanRunController extends HarbormasterController {
|
||||||
|
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$buildable->save();
|
$buildable->save();
|
||||||
$buildable->applyPlan($plan, array());
|
$buildable->applyPlan($plan, array(), $viewer->getPHID());
|
||||||
|
|
||||||
$buildable_uri = '/B'.$buildable->getID();
|
$buildable_uri = '/B'.$buildable->getID();
|
||||||
return id(new AphrontRedirectResponse())->setURI($buildable_uri);
|
return id(new AphrontRedirectResponse())->setURI($buildable_uri);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
final class HarbormasterBuildRequest extends Phobject {
|
final class HarbormasterBuildRequest extends Phobject {
|
||||||
|
|
||||||
private $buildPlanPHID;
|
private $buildPlanPHID;
|
||||||
|
private $initiatorPHID;
|
||||||
private $buildParameters = array();
|
private $buildParameters = array();
|
||||||
|
|
||||||
public function setBuildPlanPHID($build_plan_phid) {
|
public function setBuildPlanPHID($build_plan_phid) {
|
||||||
|
@ -34,4 +35,13 @@ final class HarbormasterBuildRequest extends Phobject {
|
||||||
return $this->buildParameters;
|
return $this->buildParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setInitiatorPHID($phid) {
|
||||||
|
$this->initiatorPHID = $phid;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInitiatorPHID() {
|
||||||
|
return $this->initiatorPHID;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ final class HarbormasterTargetEngine extends Phobject {
|
||||||
private $object;
|
private $object;
|
||||||
private $autoTargetKeys;
|
private $autoTargetKeys;
|
||||||
|
|
||||||
public function setViewer($viewer) {
|
public function setViewer(PhabricatorUser $viewer) {
|
||||||
$this->viewer = $viewer;
|
$this->viewer = $viewer;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,10 @@ final class HarbormasterTargetEngine extends Phobject {
|
||||||
array $step_map) {
|
array $step_map) {
|
||||||
|
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
$initiator_phid = null;
|
||||||
|
if (!$viewer->isOmnipotent()) {
|
||||||
|
$initiator_phid = $viewer->getPHID();
|
||||||
|
}
|
||||||
$plan_map = mgroup($step_map, 'getBuildPlanPHID');
|
$plan_map = mgroup($step_map, 'getBuildPlanPHID');
|
||||||
|
|
||||||
$builds = id(new HarbormasterBuildQuery())
|
$builds = id(new HarbormasterBuildQuery())
|
||||||
|
@ -206,7 +210,7 @@ final class HarbormasterTargetEngine extends Phobject {
|
||||||
// resource and "own" it, so we don't try to handle this, but may need
|
// resource and "own" it, so we don't try to handle this, but may need
|
||||||
// to be more careful here if use of autotargets expands.
|
// to be more careful here if use of autotargets expands.
|
||||||
|
|
||||||
$build = $buildable->applyPlan($plan, array());
|
$build = $buildable->applyPlan($plan, array(), $initiator_phid);
|
||||||
PhabricatorWorker::setRunAllTasksInProcess(false);
|
PhabricatorWorker::setRunAllTasksInProcess(false);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
PhabricatorWorker::setRunAllTasksInProcess(false);
|
PhabricatorWorker::setRunAllTasksInProcess(false);
|
||||||
|
|
|
@ -16,7 +16,7 @@ final class HarbormasterRunBuildPlansHeraldAction
|
||||||
return ($adapter instanceof HarbormasterBuildableAdapterInterface);
|
return ($adapter instanceof HarbormasterBuildableAdapterInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function applyBuilds(array $phids) {
|
protected function applyBuilds(array $phids, HeraldRule $rule) {
|
||||||
$adapter = $this->getAdapter();
|
$adapter = $this->getAdapter();
|
||||||
|
|
||||||
$allowed_types = array(
|
$allowed_types = array(
|
||||||
|
@ -32,7 +32,8 @@ final class HarbormasterRunBuildPlansHeraldAction
|
||||||
|
|
||||||
foreach ($phids as $phid) {
|
foreach ($phids as $phid) {
|
||||||
$request = id(new HarbormasterBuildRequest())
|
$request = id(new HarbormasterBuildRequest())
|
||||||
->setBuildPlanPHID($phid);
|
->setBuildPlanPHID($phid)
|
||||||
|
->setInitiatorPHID($rule->getPHID());
|
||||||
$adapter->queueHarbormasterBuildRequest($request);
|
$adapter->queueHarbormasterBuildRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ final class HarbormasterRunBuildPlansHeraldAction
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyEffect($object, HeraldEffect $effect) {
|
public function applyEffect($object, HeraldEffect $effect) {
|
||||||
return $this->applyBuilds($effect->getTarget());
|
return $this->applyBuilds($effect->getTarget(), $effect->getRule());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeraldActionStandardType() {
|
public function getHeraldActionStandardType() {
|
||||||
|
|
|
@ -98,7 +98,12 @@ final class HarbormasterManagementBuildWorkflow
|
||||||
PhabricatorWorker::setRunAllTasksInProcess(true);
|
PhabricatorWorker::setRunAllTasksInProcess(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$buildable->applyPlan($plan, array());
|
if ($viewer->isOmnipotent()) {
|
||||||
|
$initiator = id(new PhabricatorHarbormasterApplication())->getPHID();
|
||||||
|
} else {
|
||||||
|
$initiator = $viewer->getPHID();
|
||||||
|
}
|
||||||
|
$buildable->applyPlan($plan, array(), $initiator);
|
||||||
|
|
||||||
$console->writeOut("%s\n", pht('Done.'));
|
$console->writeOut("%s\n", pht('Done.'));
|
||||||
|
|
||||||
|
|
|
@ -154,11 +154,14 @@ final class HarbormasterBuildable extends HarbormasterDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
$parameters = $request->getBuildParameters();
|
$parameters = $request->getBuildParameters();
|
||||||
$buildable->applyPlan($plan, $parameters);
|
$buildable->applyPlan($plan, $parameters, $request->getInitiatorPHID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyPlan(HarbormasterBuildPlan $plan, array $parameters) {
|
public function applyPlan(
|
||||||
|
HarbormasterBuildPlan $plan,
|
||||||
|
array $parameters,
|
||||||
|
$initiator_phid) {
|
||||||
|
|
||||||
$viewer = PhabricatorUser::getOmnipotentUser();
|
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||||
$build = HarbormasterBuild::initializeNewBuild($viewer)
|
$build = HarbormasterBuild::initializeNewBuild($viewer)
|
||||||
|
@ -166,6 +169,9 @@ final class HarbormasterBuildable extends HarbormasterDAO
|
||||||
->setBuildPlanPHID($plan->getPHID())
|
->setBuildPlanPHID($plan->getPHID())
|
||||||
->setBuildParameters($parameters)
|
->setBuildParameters($parameters)
|
||||||
->setBuildStatus(HarbormasterBuild::STATUS_PENDING);
|
->setBuildStatus(HarbormasterBuild::STATUS_PENDING);
|
||||||
|
if ($initiator_phid) {
|
||||||
|
$build->setInitiatorPHID($initiator_phid);
|
||||||
|
}
|
||||||
|
|
||||||
$auto_key = $plan->getPlanAutoKey();
|
$auto_key = $plan->getPlanAutoKey();
|
||||||
if ($auto_key) {
|
if ($auto_key) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
protected $buildStatus;
|
protected $buildStatus;
|
||||||
protected $buildGeneration;
|
protected $buildGeneration;
|
||||||
protected $buildParameters = array();
|
protected $buildParameters = array();
|
||||||
|
protected $initiatorPHID;
|
||||||
protected $planAutoKey;
|
protected $planAutoKey;
|
||||||
|
|
||||||
private $buildable = self::ATTACHABLE;
|
private $buildable = self::ATTACHABLE;
|
||||||
|
@ -164,6 +165,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
'buildStatus' => 'text32',
|
'buildStatus' => 'text32',
|
||||||
'buildGeneration' => 'uint32',
|
'buildGeneration' => 'uint32',
|
||||||
'planAutoKey' => 'text32?',
|
'planAutoKey' => 'text32?',
|
||||||
|
'initiatorPHID' => 'phid?',
|
||||||
),
|
),
|
||||||
self::CONFIG_KEY_SCHEMA => array(
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
'key_buildable' => array(
|
'key_buildable' => array(
|
||||||
|
@ -260,6 +262,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
'repository.uri' => null,
|
'repository.uri' => null,
|
||||||
'step.timestamp' => null,
|
'step.timestamp' => null,
|
||||||
'build.id' => null,
|
'build.id' => null,
|
||||||
|
'initiator.phid' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($this->getBuildParameters() as $key => $value) {
|
foreach ($this->getBuildParameters() as $key => $value) {
|
||||||
|
@ -275,6 +278,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
|
|
||||||
$results['step.timestamp'] = time();
|
$results['step.timestamp'] = time();
|
||||||
$results['build.id'] = $this->getID();
|
$results['build.id'] = $this->getID();
|
||||||
|
$results['initiator.phid'] = $this->getInitiatorPHID();
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
@ -289,6 +293,9 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
'step.timestamp' => pht('The current UNIX timestamp.'),
|
'step.timestamp' => pht('The current UNIX timestamp.'),
|
||||||
'build.id' => pht('The ID of the current build.'),
|
'build.id' => pht('The ID of the current build.'),
|
||||||
'target.phid' => pht('The PHID of the current build target.'),
|
'target.phid' => pht('The PHID of the current build target.'),
|
||||||
|
'initiator.phid' => pht(
|
||||||
|
'The PHID of the user or Object that initiated the build, '.
|
||||||
|
'if applicable.'),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($objects as $object) {
|
foreach ($objects as $object) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue