Page MenuHomePhabricator

D13099.id31625.diff
No OneTemporary

D13099.id31625.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -178,6 +178,7 @@
'ArcanistTextLinterTestCase' => 'lint/linter/__tests__/ArcanistTextLinterTestCase.php',
'ArcanistTimeWorkflow' => 'workflow/ArcanistTimeWorkflow.php',
'ArcanistTodoWorkflow' => 'workflow/ArcanistTodoWorkflow.php',
+ 'ArcanistTryWorkflow' => 'workflow/ArcanistTryWorkflow.php',
'ArcanistUSEnglishTranslation' => 'internationalization/ArcanistUSEnglishTranslation.php',
'ArcanistUnitConsoleRenderer' => 'unit/renderer/ArcanistUnitConsoleRenderer.php',
'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php',
@@ -355,6 +356,7 @@
'ArcanistTextLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistTimeWorkflow' => 'ArcanistPhrequentWorkflow',
'ArcanistTodoWorkflow' => 'ArcanistWorkflow',
+ 'ArcanistTryWorkflow' => 'ArcanistWorkflow',
'ArcanistUSEnglishTranslation' => 'PhutilTranslation',
'ArcanistUnitConsoleRenderer' => 'ArcanistUnitRenderer',
'ArcanistUnitTestableLintEngine' => 'ArcanistLintEngine',
diff --git a/src/workflow/ArcanistTryWorkflow.php b/src/workflow/ArcanistTryWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/workflow/ArcanistTryWorkflow.php
@@ -0,0 +1,110 @@
+<?php
+
+/**
+ * Pushes the current HEAD to a staging repository for a test build.
+ *
+ * @concrete-extensible
+ */
+class ArcanistTryWorkflow extends ArcanistWorkflow {
+
+ private $branches;
+
+ public function getWorkflowName() {
+ return 'try';
+ }
+
+ public function getCommandSynopses() {
+ return phutil_console_format(<<<EOTEXT
+ **try** [__options__]
+EOTEXT
+ );
+ }
+
+ public function getCommandHelp() {
+ return phutil_console_format(<<<EOTEXT
+ Supports: git
+ Runs a build on the Phabricator server using the current HEAD of
+ this repository, without creating a revision.
+EOTEXT
+ );
+ }
+
+ public function requiresConduit() {
+ return true;
+ }
+
+ public function requiresAuthentication() {
+ return true;
+ }
+
+ public function requiresRepositoryAPI() {
+ return true;
+ }
+
+ public function getArguments() {
+ return array();
+ }
+
+ public function getSupportedRevisionControlSystems() {
+ return array('git');
+ }
+
+ public function run() {
+ $conduit = $this->getConduit();
+ $api = $this->getRepositoryAPI();
+ $staging = $this->getRepositoryStaging();
+
+ if ($staging == null || !idx($staging, 'supported', false)) {
+ throw new ArcanistUsageException(pht(
+ 'This project does not have a staging repository.'));
+ }
+
+ $build_plan_id = $this->getConfigFromAnySource('try.buildplanid');
+
+ if ($build_plan_id === null) {
+ throw new ArcanistUsageException(pht(
+ 'No build plan ID configured for project; set '.
+ '\'try.buildplanid\' in .arcconfig first.'));
+ }
+
+ $uri = idx($staging, 'uri');
+
+ echo pht("Pushing HEAD to staging repository...\n");
+
+ $api->execxLocal(
+ 'push -f %s HEAD:temporary-%s',
+ $uri,
+ Filesystem::readRandomCharacters(20));
+
+ list($commit_ref, $stderr) = $api->execxLocal('rev-parse HEAD');
+
+ echo pht(
+ "Scheduling build plan %d on %s...\n",
+ $build_plan_id,
+ trim($commit_ref));
+
+ $url = null;
+ while (true) {
+ try {
+ $url = $conduit->callMethodSynchronous(
+ 'harbormaster.startmanualbuild',
+ array(
+ 'commitIdentifier' => trim($commit_ref),
+ 'buildPlanID' => $build_plan_id,
+ ));
+ break;
+ } catch (ConduitClientException $ex) {
+ if (substr_count($ex->getMessage(), 'No such commit!') > 0) {
+ echo pht("Commit not yet parsed (waiting 5 seconds)...\n");
+ sleep(5);
+ }
+ }
+ }
+
+ echo pht("Build started at %s\n", $url);
+
+ return 0;
+ }
+
+
+}
diff --git a/src/workflow/ArcanistWorkflow.php b/src/workflow/ArcanistWorkflow.php
--- a/src/workflow/ArcanistWorkflow.php
+++ b/src/workflow/ArcanistWorkflow.php
@@ -1704,6 +1704,19 @@
/**
+ * Get the staging information of the Phabricator repository this
+ * working copy corresponds to.
+ *
+ * @return array|null Repository staging information, if present.
+ *
+ * @task phabrep
+ */
+ final protected function getRepositoryStaging() {
+ return idx($this->getRepositoryInformation(), 'staging');
+ }
+
+
+ /**
* Get human-readable reasoning explaining how `arc` evaluated which
* Phabricator repository corresponds to this working copy. Used by
* `arc which` to explain the process to users.

File Metadata

Mime Type
text/plain
Expires
Thu, Mar 6, 3:14 PM (3 d, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7274951
Default Alt Text
D13099.id31625.diff (4 KB)

Event Timeline