From f1ba27ffedd5e74174707923c614ce5bb06071cf Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 27 Oct 2017 10:12:50 -0700 Subject: [PATCH] Add "arc diff --draft" Summary: Experimental branch. Ref T2543. Depends on D18742. Add an "arc diff --draft" flag which holds revisions as drafts indefinitely. Test Plan: Ran "arc diff --draft" when creating; ran "arc diff --draft" to try to update a revision and got a failure. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T2543 Differential Revision: https://secure.phabricator.com/D18743 --- .../ArcanistDifferentialCommitMessage.php | 7 ++++ src/workflow/ArcanistDiffWorkflow.php | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/differential/ArcanistDifferentialCommitMessage.php b/src/differential/ArcanistDifferentialCommitMessage.php index 132ddadf..912ee4be 100644 --- a/src/differential/ArcanistDifferentialCommitMessage.php +++ b/src/differential/ArcanistDifferentialCommitMessage.php @@ -38,6 +38,13 @@ final class ArcanistDifferentialCommitMessage extends Phobject { return $this->revisionID; } + public function getRevisionMonogram() { + if ($this->revisionID) { + return 'D'.$this->revisionID; + } + return null; + } + public function pullDataFromConduit( ConduitClient $conduit, $partial = false) { diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 9f891c1f..7e1d7b18 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -190,6 +190,16 @@ EOTEXT 'param' => 'revision_id', 'help' => pht('Always update a specific revision.'), ), + 'draft' => array( + 'help' => pht( + 'Hold this revision as a draft instead of submitting it for '. + 'review.'), + 'conflicts' => array( + 'edit' => null, + 'only' => null, + 'update' => null, + ), + ), 'nounit' => array( 'help' => pht('Do not run unit tests.'), ), @@ -511,9 +521,21 @@ EOTEXT $this->openURIsInBrowser(array($diff_info['uri'])); } } else { + $is_draft = $this->getArgument('draft'); $revision['diffid'] = $this->getDiffID(); if ($commit_message->getRevisionID()) { + if ($is_draft) { + // TODO: In at least some cases, we could raise this earlier in the + // workflow to save users some time before the workflow aborts. + throw new ArcanistUsageException( + pht( + 'You are updating a revision ("%s") but have specified '. + 'the "--draft" flag. Only newly created revisions can be '. + 'held as drafts.', + $commit_message->getRevisionMonogram())); + } + $result = $conduit->callMethodSynchronous( 'differential.updaterevision', $revision); @@ -524,6 +546,9 @@ EOTEXT $this->writeScratchJSONFile($file, $messages); } + $result_uri = $result['uri']; + $result_id = $result['revisionid']; + echo pht('Updated an existing Differential revision:')."\n"; } else { // NOTE: We're either using "differential.revision.edit" (preferred) @@ -537,6 +562,13 @@ EOTEXT 'value' => $diff_info['phid'], ); + if ($is_draft) { + $xactions[] = array( + 'type' => 'draft', + 'value' => true, + ); + } + $result = $conduit->callMethodSynchronous( 'differential.revision.edit', array( @@ -556,6 +588,14 @@ EOTEXT $result_uri = id(new PhutilURI($this->getConduitURI())) ->setPath('/D'.$result_id); } else { + if ($is_draft) { + throw new ArcanistUsageException( + pht( + 'You have specified "--draft", but the version of Phabricator '. + 'on the server is too old to support draft revisions. Omit '. + 'the flag or upgrade the server software.')); + } + $revision = $this->dispatchWillCreateRevisionEvent($revision); $result = $conduit->callMethodSynchronous(