@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.

Make all build steps support variables

Summary: Ref T1049. This generally simplifies things. The steps which don't support variables generally don't make sense to support varaibles anyway.

Test Plan: Edited some steps.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1049

Differential Revision: https://secure.phabricator.com/D8588

+76 -84
+4 -6
src/__phutil_library_map__.php
··· 2537 2537 'SubscriptionListDialogBuilder' => 'applications/subscriptions/view/SubscriptionListDialogBuilder.php', 2538 2538 'SubscriptionListStringBuilder' => 'applications/subscriptions/view/SubscriptionListStringBuilder.php', 2539 2539 'UploadArtifactBuildStepImplementation' => 'applications/harbormaster/step/UploadArtifactBuildStepImplementation.php', 2540 - 'VariableBuildStepImplementation' => 'applications/harbormaster/step/VariableBuildStepImplementation.php', 2541 2540 'WaitForPreviousBuildStepImplementation' => 'applications/harbormaster/step/WaitForPreviousBuildStepImplementation.php', 2542 2541 ), 2543 2542 'function' => ··· 2659 2658 'CelerityResourceGraph' => 'AbstractDirectedGraph', 2660 2659 'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase', 2661 2660 'CelerityResourcesOnDisk' => 'CelerityPhysicalResources', 2662 - 'CommandBuildStepImplementation' => 'VariableBuildStepImplementation', 2661 + 'CommandBuildStepImplementation' => 'BuildStepImplementation', 2663 2662 'ConduitAPIMethod' => 2664 2663 array( 2665 2664 0 => 'Phobject', ··· 3339 3338 'HarbormasterCapabilityManagePlans' => 'PhabricatorPolicyCapability', 3340 3339 'HarbormasterController' => 'PhabricatorController', 3341 3340 'HarbormasterDAO' => 'PhabricatorLiskDAO', 3342 - 'HarbormasterHTTPRequestBuildStepImplementation' => 'VariableBuildStepImplementation', 3341 + 'HarbormasterHTTPRequestBuildStepImplementation' => 'BuildStepImplementation', 3343 3342 'HarbormasterManagementBuildWorkflow' => 'HarbormasterManagementWorkflow', 3344 3343 'HarbormasterManagementWorkflow' => 'PhabricatorManagementWorkflow', 3345 3344 'HarbormasterObject' => 'HarbormasterDAO', ··· 5384 5383 'PonderVoteSaveController' => 'PonderController', 5385 5384 'ProjectCapabilityCreateProjects' => 'PhabricatorPolicyCapability', 5386 5385 'ProjectRemarkupRule' => 'PhabricatorRemarkupRuleObject', 5387 - 'PublishFragmentBuildStepImplementation' => 'VariableBuildStepImplementation', 5386 + 'PublishFragmentBuildStepImplementation' => 'BuildStepImplementation', 5388 5387 'QueryFormattingTestCase' => 'PhabricatorTestCase', 5389 5388 'ReleephAuthorFieldSpecification' => 'ReleephFieldSpecification', 5390 5389 'ReleephBranch' => ··· 5491 5490 'SleepBuildStepImplementation' => 'BuildStepImplementation', 5492 5491 'SlowvoteEmbedView' => 'AphrontView', 5493 5492 'SlowvoteRemarkupRule' => 'PhabricatorRemarkupRuleObject', 5494 - 'UploadArtifactBuildStepImplementation' => 'VariableBuildStepImplementation', 5495 - 'VariableBuildStepImplementation' => 'BuildStepImplementation', 5493 + 'UploadArtifactBuildStepImplementation' => 'BuildStepImplementation', 5496 5494 'WaitForPreviousBuildStepImplementation' => 'BuildStepImplementation', 5497 5495 ), 5498 5496 ));
+33 -15
src/applications/harbormaster/controller/HarbormasterStepEditController.php
··· 24 24 return new Aphront404Response(); 25 25 } 26 26 27 - $plan = id(new HarbormasterBuildPlanQuery()) 28 - ->setViewer($viewer) 29 - ->withPHIDs(array($step->getBuildPlanPHID())) 30 - ->executeOne(); 31 - if (!$plan) { 32 - return new Aphront404Response(); 33 - } 27 + $plan = $step->getBuildPlan(); 34 28 35 29 $implementation = $step->getStepImplementation(); 36 30 $implementation->validateSettingDefinitions(); ··· 52 46 } 53 47 } 54 48 55 - if (count($errors) === 0) { 49 + if (!$errors) { 56 50 $step->save(); 57 - 58 51 return id(new AphrontRedirectResponse()) 59 52 ->setURI($this->getApplicationURI('plan/'.$plan->getID().'/')); 60 53 } ··· 63 56 $form = id(new AphrontFormView()) 64 57 ->setUser($viewer); 65 58 66 - $instructions = $implementation->getSettingRemarkupInstructions(); 67 - if ($instructions !== null) { 68 - $form->appendRemarkupInstructions($instructions); 69 - } 70 - 71 59 // We need to render out all of the fields for the settings that 72 60 // the implementation has. 73 61 foreach ($implementation->getSettingDefinitions() as $name => $opt) { ··· 121 109 122 110 $form->appendChild( 123 111 id(new AphrontFormSubmitControl()) 124 - ->setValue(pht('Save Step Configuration')) 112 + ->setValue(pht('Save Build Step')) 125 113 ->addCancelButton( 126 114 $this->getApplicationURI('plan/'.$plan->getID().'/'))); 127 115 ··· 137 125 $this->getApplicationURI("plan/{$id}/")); 138 126 $crumbs->addTextCrumb(pht('Edit Step')); 139 127 128 + $variables = $this->renderBuildVariablesTable(); 129 + 140 130 return $this->buildApplicationPage( 141 131 array( 142 132 $crumbs, 143 133 $box, 134 + $variables, 144 135 ), 145 136 array( 146 137 'title' => $implementation->getName(), ··· 172 163 throw new Exception("Unsupported setting type '".$type."'."); 173 164 } 174 165 } 166 + 167 + private function renderBuildVariablesTable() { 168 + $viewer = $this->getRequest()->getUser(); 169 + 170 + $variables = HarbormasterBuild::getAvailableBuildVariables(); 171 + ksort($variables); 172 + 173 + $rows = array(); 174 + $rows[] = pht( 175 + 'The following variables can be used in most fields. To reference '. 176 + 'a variable, use `${name}` in a field.'); 177 + $rows[] = pht('| Variable | Description |'); 178 + $rows[] = '|---|---|'; 179 + foreach ($variables as $name => $description) { 180 + $rows[] = '| `'.$name.'` | '.$description.' |'; 181 + } 182 + $rows = implode("\n", $rows); 183 + 184 + $form = id(new AphrontFormView()) 185 + ->setUser($viewer) 186 + ->appendRemarkupInstructions($rows); 187 + 188 + return id(new PHUIObjectBoxView()) 189 + ->setHeaderText(pht('Build Variables')) 190 + ->appendChild($form); 191 + } 192 + 175 193 176 194 }
+35 -7
src/applications/harbormaster/step/BuildStepImplementation.php
··· 91 91 } 92 92 93 93 /** 94 - * Return relevant setting instructions as Remarkup. 95 - */ 96 - public function getSettingRemarkupInstructions() { 97 - return null; 98 - } 99 - 100 - /** 101 94 * Return the name of artifacts produced by this command. 102 95 * 103 96 * Something like: ··· 160 153 } 161 154 return $artifacts; 162 155 } 156 + 157 + /** 158 + * Convert a user-provided string with variables in it, like: 159 + * 160 + * ls ${dirname} 161 + * 162 + * ...into a string with variables merged into it safely: 163 + * 164 + * ls 'dir with spaces' 165 + * 166 + * @param string Name of a `vxsprintf` function, like @{function:vcsprintf}. 167 + * @param string User-provided pattern string containing `${variables}`. 168 + * @param dict List of available replacement variables. 169 + * @return string String with variables replaced safely into it. 170 + */ 171 + protected function mergeVariables($function, $pattern, array $variables) { 172 + $regexp = '/\\$\\{(?P<name>[a-z\\.]+)\\}/'; 173 + 174 + $matches = null; 175 + preg_match_all($regexp, $pattern, $matches); 176 + 177 + $argv = array(); 178 + foreach ($matches['name'] as $name) { 179 + if (!array_key_exists($name, $variables)) { 180 + throw new Exception(pht("No such variable '%s'!", $name)); 181 + } 182 + $argv[] = $variables[$name]; 183 + } 184 + 185 + $pattern = str_replace('%', '%%', $pattern); 186 + $pattern = preg_replace($regexp, '%s', $pattern); 187 + 188 + return call_user_func($function, $pattern, $argv); 189 + } 190 + 163 191 }
+1 -1
src/applications/harbormaster/step/CommandBuildStepImplementation.php
··· 1 1 <?php 2 2 3 3 final class CommandBuildStepImplementation 4 - extends VariableBuildStepImplementation { 4 + extends BuildStepImplementation { 5 5 6 6 public function getName() { 7 7 return pht('Run Command');
+1 -1
src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php
··· 1 1 <?php 2 2 3 3 final class HarbormasterHTTPRequestBuildStepImplementation 4 - extends VariableBuildStepImplementation { 4 + extends BuildStepImplementation { 5 5 6 6 public function getName() { 7 7 return pht('Make HTTP Request');
+1 -1
src/applications/harbormaster/step/PublishFragmentBuildStepImplementation.php
··· 1 1 <?php 2 2 3 3 final class PublishFragmentBuildStepImplementation 4 - extends VariableBuildStepImplementation { 4 + extends BuildStepImplementation { 5 5 6 6 public function getName() { 7 7 return pht('Publish Fragment');
+1 -1
src/applications/harbormaster/step/UploadArtifactBuildStepImplementation.php
··· 1 1 <?php 2 2 3 3 final class UploadArtifactBuildStepImplementation 4 - extends VariableBuildStepImplementation { 4 + extends BuildStepImplementation { 5 5 6 6 public function getName() { 7 7 return pht('Upload Artifact');
-52
src/applications/harbormaster/step/VariableBuildStepImplementation.php
··· 1 - <?php 2 - 3 - abstract class VariableBuildStepImplementation extends BuildStepImplementation { 4 - 5 - /** 6 - * Convert a user-provided string with variables in it, like: 7 - * 8 - * ls ${dirname} 9 - * 10 - * ...into a string with variables merged into it safely: 11 - * 12 - * ls 'dir with spaces' 13 - * 14 - * @param string Name of a `vxsprintf` function, like @{function:vcsprintf}. 15 - * @param string User-provided pattern string containing `${variables}`. 16 - * @param dict List of available replacement variables. 17 - * @return string String with variables replaced safely into it. 18 - */ 19 - protected function mergeVariables($function, $pattern, array $variables) { 20 - $regexp = '/\\$\\{(?P<name>[a-z\\.]+)\\}/'; 21 - 22 - $matches = null; 23 - preg_match_all($regexp, $pattern, $matches); 24 - 25 - $argv = array(); 26 - foreach ($matches['name'] as $name) { 27 - if (!array_key_exists($name, $variables)) { 28 - throw new Exception(pht("No such variable '%s'!", $name)); 29 - } 30 - $argv[] = $variables[$name]; 31 - } 32 - 33 - $pattern = str_replace('%', '%%', $pattern); 34 - $pattern = preg_replace($regexp, '%s', $pattern); 35 - 36 - return call_user_func($function, $pattern, $argv); 37 - } 38 - 39 - public function getSettingRemarkupInstructions() { 40 - $variables = HarbormasterBuild::getAvailableBuildVariables(); 41 - $text = ''; 42 - $text .= pht('The following variables are available: ')."\n"; 43 - $text .= "\n"; 44 - foreach ($variables as $name => $desc) { 45 - $text .= ' - `'.$name.'`: '.$desc."\n"; 46 - } 47 - $text .= "\n"; 48 - $text .= "Use `\${name}` to merge a variable into a setting."; 49 - return $text; 50 - } 51 - 52 - }