Page MenuHomePhabricator

D14380.id34732.diff
No OneTemporary

D14380.id34732.diff

diff --git a/resources/sql/autopatches/20151030.harbormaster.initiator.sql b/resources/sql/autopatches/20151030.harbormaster.initiator.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20151030.harbormaster.initiator.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_build
+ ADD COLUMN initiatorPHID VARBINARY(64);
diff --git a/src/applications/harbormaster/controller/HarbormasterPlanRunController.php b/src/applications/harbormaster/controller/HarbormasterPlanRunController.php
--- a/src/applications/harbormaster/controller/HarbormasterPlanRunController.php
+++ b/src/applications/harbormaster/controller/HarbormasterPlanRunController.php
@@ -59,7 +59,7 @@
if (!$errors) {
$buildable->save();
- $buildable->applyPlan($plan, array());
+ $buildable->applyPlan($plan, array(), $viewer->getPHID());
$buildable_uri = '/B'.$buildable->getID();
return id(new AphrontRedirectResponse())->setURI($buildable_uri);
diff --git a/src/applications/harbormaster/engine/HarbormasterBuildRequest.php b/src/applications/harbormaster/engine/HarbormasterBuildRequest.php
--- a/src/applications/harbormaster/engine/HarbormasterBuildRequest.php
+++ b/src/applications/harbormaster/engine/HarbormasterBuildRequest.php
@@ -14,6 +14,7 @@
final class HarbormasterBuildRequest extends Phobject {
private $buildPlanPHID;
+ private $initiatorPHID;
private $buildParameters = array();
public function setBuildPlanPHID($build_plan_phid) {
@@ -34,4 +35,13 @@
return $this->buildParameters;
}
+ public function setInitiatorPHID($phid) {
+ $this->initiatorPHID = $phid;
+ return $this;
+ }
+
+ public function getInitiatorPHID() {
+ return $this->initiatorPHID;
+ }
+
}
diff --git a/src/applications/harbormaster/engine/HarbormasterTargetEngine.php b/src/applications/harbormaster/engine/HarbormasterTargetEngine.php
--- a/src/applications/harbormaster/engine/HarbormasterTargetEngine.php
+++ b/src/applications/harbormaster/engine/HarbormasterTargetEngine.php
@@ -6,7 +6,7 @@
private $object;
private $autoTargetKeys;
- public function setViewer($viewer) {
+ public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
@@ -163,6 +163,10 @@
array $step_map) {
$viewer = $this->getViewer();
+ $initiator_phid = null;
+ if (!$viewer->isOmnipotent()) {
+ $initiator_phid = $viewer->getPHID();
+ }
$plan_map = mgroup($step_map, 'getBuildPlanPHID');
$builds = id(new HarbormasterBuildQuery())
@@ -206,7 +210,7 @@
// 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.
- $build = $buildable->applyPlan($plan, array());
+ $build = $buildable->applyPlan($plan, array(), $initiator_phid);
PhabricatorWorker::setRunAllTasksInProcess(false);
} catch (Exception $ex) {
PhabricatorWorker::setRunAllTasksInProcess(false);
diff --git a/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php b/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php
--- a/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php
+++ b/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php
@@ -16,7 +16,7 @@
return ($adapter instanceof HarbormasterBuildableAdapterInterface);
}
- protected function applyBuilds(array $phids) {
+ protected function applyBuilds(array $phids, HeraldRule $rule) {
$adapter = $this->getAdapter();
$allowed_types = array(
@@ -32,7 +32,8 @@
foreach ($phids as $phid) {
$request = id(new HarbormasterBuildRequest())
- ->setBuildPlanPHID($phid);
+ ->setBuildPlanPHID($phid)
+ ->setInitiatorPHID($rule->getPHID());
$adapter->queueHarbormasterBuildRequest($request);
}
@@ -68,7 +69,7 @@
}
public function applyEffect($object, HeraldEffect $effect) {
- return $this->applyBuilds($effect->getTarget());
+ return $this->applyBuilds($effect->getTarget(), $effect->getRule());
}
public function getHeraldActionStandardType() {
diff --git a/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php b/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php
--- a/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php
+++ b/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php
@@ -98,7 +98,12 @@
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.'));
diff --git a/src/applications/harbormaster/storage/HarbormasterBuildable.php b/src/applications/harbormaster/storage/HarbormasterBuildable.php
--- a/src/applications/harbormaster/storage/HarbormasterBuildable.php
+++ b/src/applications/harbormaster/storage/HarbormasterBuildable.php
@@ -154,11 +154,14 @@
}
$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();
$build = HarbormasterBuild::initializeNewBuild($viewer)
@@ -166,6 +169,9 @@
->setBuildPlanPHID($plan->getPHID())
->setBuildParameters($parameters)
->setBuildStatus(HarbormasterBuild::STATUS_PENDING);
+ if ($initiator_phid) {
+ $build->setInitiatorPHID($initiator_phid);
+ }
$auto_key = $plan->getPlanAutoKey();
if ($auto_key) {
diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php
--- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php
+++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php
@@ -10,6 +10,7 @@
protected $buildStatus;
protected $buildGeneration;
protected $buildParameters = array();
+ protected $initiatorPHID;
protected $planAutoKey;
private $buildable = self::ATTACHABLE;
@@ -164,6 +165,7 @@
'buildStatus' => 'text32',
'buildGeneration' => 'uint32',
'planAutoKey' => 'text32?',
+ 'initiatorPHID' => 'phid?',
),
self::CONFIG_KEY_SCHEMA => array(
'key_buildable' => array(
@@ -260,6 +262,7 @@
'repository.uri' => null,
'step.timestamp' => null,
'build.id' => null,
+ 'initiator.phid' => null,
);
foreach ($this->getBuildParameters() as $key => $value) {
@@ -275,6 +278,7 @@
$results['step.timestamp'] = time();
$results['build.id'] = $this->getID();
+ $results['initiator.phid'] = $this->getInitiatorPHID();
return $results;
}
@@ -289,6 +293,9 @@
'step.timestamp' => pht('The current UNIX timestamp.'),
'build.id' => pht('The ID of the current build.'),
'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) {

File Metadata

Mime Type
text/plain
Expires
Oct 16 2024, 12:10 AM (4 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6715024
Default Alt Text
D14380.id34732.diff (7 KB)

Event Timeline