@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Aviv Eyal and committed by
avivey
1898864b 5c6d2be1

+44 -9
+2
resources/sql/autopatches/20151030.harbormaster.initiator.sql
··· 1 + ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_build 2 + ADD COLUMN initiatorPHID VARBINARY(64);
+1 -1
src/applications/harbormaster/controller/HarbormasterPlanRunController.php
··· 59 59 60 60 if (!$errors) { 61 61 $buildable->save(); 62 - $buildable->applyPlan($plan, array()); 62 + $buildable->applyPlan($plan, array(), $viewer->getPHID()); 63 63 64 64 $buildable_uri = '/B'.$buildable->getID(); 65 65 return id(new AphrontRedirectResponse())->setURI($buildable_uri);
+10
src/applications/harbormaster/engine/HarbormasterBuildRequest.php
··· 14 14 final class HarbormasterBuildRequest extends Phobject { 15 15 16 16 private $buildPlanPHID; 17 + private $initiatorPHID; 17 18 private $buildParameters = array(); 18 19 19 20 public function setBuildPlanPHID($build_plan_phid) { ··· 32 33 33 34 public function getBuildParameters() { 34 35 return $this->buildParameters; 36 + } 37 + 38 + public function setInitiatorPHID($phid) { 39 + $this->initiatorPHID = $phid; 40 + return $this; 41 + } 42 + 43 + public function getInitiatorPHID() { 44 + return $this->initiatorPHID; 35 45 } 36 46 37 47 }
+6 -2
src/applications/harbormaster/engine/HarbormasterTargetEngine.php
··· 6 6 private $object; 7 7 private $autoTargetKeys; 8 8 9 - public function setViewer($viewer) { 9 + public function setViewer(PhabricatorUser $viewer) { 10 10 $this->viewer = $viewer; 11 11 return $this; 12 12 } ··· 163 163 array $step_map) { 164 164 165 165 $viewer = $this->getViewer(); 166 + $initiator_phid = null; 167 + if (!$viewer->isOmnipotent()) { 168 + $initiator_phid = $viewer->getPHID(); 169 + } 166 170 $plan_map = mgroup($step_map, 'getBuildPlanPHID'); 167 171 168 172 $builds = id(new HarbormasterBuildQuery()) ··· 206 210 // resource and "own" it, so we don't try to handle this, but may need 207 211 // to be more careful here if use of autotargets expands. 208 212 209 - $build = $buildable->applyPlan($plan, array()); 213 + $build = $buildable->applyPlan($plan, array(), $initiator_phid); 210 214 PhabricatorWorker::setRunAllTasksInProcess(false); 211 215 } catch (Exception $ex) { 212 216 PhabricatorWorker::setRunAllTasksInProcess(false);
+4 -3
src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php
··· 16 16 return ($adapter instanceof HarbormasterBuildableAdapterInterface); 17 17 } 18 18 19 - protected function applyBuilds(array $phids) { 19 + protected function applyBuilds(array $phids, HeraldRule $rule) { 20 20 $adapter = $this->getAdapter(); 21 21 22 22 $allowed_types = array( ··· 32 32 33 33 foreach ($phids as $phid) { 34 34 $request = id(new HarbormasterBuildRequest()) 35 - ->setBuildPlanPHID($phid); 35 + ->setBuildPlanPHID($phid) 36 + ->setInitiatorPHID($rule->getPHID()); 36 37 $adapter->queueHarbormasterBuildRequest($request); 37 38 } 38 39 ··· 68 69 } 69 70 70 71 public function applyEffect($object, HeraldEffect $effect) { 71 - return $this->applyBuilds($effect->getTarget()); 72 + return $this->applyBuilds($effect->getTarget(), $effect->getRule()); 72 73 } 73 74 74 75 public function getHeraldActionStandardType() {
+6 -1
src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php
··· 98 98 PhabricatorWorker::setRunAllTasksInProcess(true); 99 99 } 100 100 101 - $buildable->applyPlan($plan, array()); 101 + if ($viewer->isOmnipotent()) { 102 + $initiator = id(new PhabricatorHarbormasterApplication())->getPHID(); 103 + } else { 104 + $initiator = $viewer->getPHID(); 105 + } 106 + $buildable->applyPlan($plan, array(), $initiator); 102 107 103 108 $console->writeOut("%s\n", pht('Done.')); 104 109
+8 -2
src/applications/harbormaster/storage/HarbormasterBuildable.php
··· 154 154 } 155 155 156 156 $parameters = $request->getBuildParameters(); 157 - $buildable->applyPlan($plan, $parameters); 157 + $buildable->applyPlan($plan, $parameters, $request->getInitiatorPHID()); 158 158 } 159 159 } 160 160 161 - public function applyPlan(HarbormasterBuildPlan $plan, array $parameters) { 161 + public function applyPlan( 162 + HarbormasterBuildPlan $plan, 163 + array $parameters, 164 + $initiator_phid) { 162 165 163 166 $viewer = PhabricatorUser::getOmnipotentUser(); 164 167 $build = HarbormasterBuild::initializeNewBuild($viewer) ··· 166 169 ->setBuildPlanPHID($plan->getPHID()) 167 170 ->setBuildParameters($parameters) 168 171 ->setBuildStatus(HarbormasterBuild::STATUS_PENDING); 172 + if ($initiator_phid) { 173 + $build->setInitiatorPHID($initiator_phid); 174 + } 169 175 170 176 $auto_key = $plan->getPlanAutoKey(); 171 177 if ($auto_key) {
+7
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 10 10 protected $buildStatus; 11 11 protected $buildGeneration; 12 12 protected $buildParameters = array(); 13 + protected $initiatorPHID; 13 14 protected $planAutoKey; 14 15 15 16 private $buildable = self::ATTACHABLE; ··· 164 165 'buildStatus' => 'text32', 165 166 'buildGeneration' => 'uint32', 166 167 'planAutoKey' => 'text32?', 168 + 'initiatorPHID' => 'phid?', 167 169 ), 168 170 self::CONFIG_KEY_SCHEMA => array( 169 171 'key_buildable' => array( ··· 260 262 'repository.uri' => null, 261 263 'step.timestamp' => null, 262 264 'build.id' => null, 265 + 'initiator.phid' => null, 263 266 ); 264 267 265 268 foreach ($this->getBuildParameters() as $key => $value) { ··· 275 278 276 279 $results['step.timestamp'] = time(); 277 280 $results['build.id'] = $this->getID(); 281 + $results['initiator.phid'] = $this->getInitiatorPHID(); 278 282 279 283 return $results; 280 284 } ··· 289 293 'step.timestamp' => pht('The current UNIX timestamp.'), 290 294 'build.id' => pht('The ID of the current build.'), 291 295 'target.phid' => pht('The PHID of the current build target.'), 296 + 'initiator.phid' => pht( 297 + 'The PHID of the user or Object that initiated the build, '. 298 + 'if applicable.'), 292 299 ); 293 300 294 301 foreach ($objects as $object) {