Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistDiffWorkflow.php
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | $arguments = array( | ||||
'--create', | '--create', | ||||
'--update'), | '--update'), | ||||
), | ), | ||||
), | ), | ||||
'update' => array( | 'update' => array( | ||||
'param' => 'revision_id', | 'param' => 'revision_id', | ||||
'help' => pht('Always update a specific revision.'), | '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( | 'nounit' => array( | ||||
'help' => pht('Do not run unit tests.'), | 'help' => pht('Do not run unit tests.'), | ||||
), | ), | ||||
'nolint' => array( | 'nolint' => array( | ||||
'help' => pht('Do not run lint.'), | 'help' => pht('Do not run lint.'), | ||||
'conflicts' => array( | 'conflicts' => array( | ||||
'lintall' => pht('%s suppresses lint.', '--nolint'), | 'lintall' => pht('%s suppresses lint.', '--nolint'), | ||||
'advice' => pht('%s suppresses lint.', '--nolint'), | 'advice' => pht('%s suppresses lint.', '--nolint'), | ||||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | if ($this->shouldOnlyCreateDiff()) { | ||||
))."\n"; | ))."\n"; | ||||
ob_start(); | ob_start(); | ||||
} | } | ||||
if ($this->shouldOpenCreatedObjectsInBrowser()) { | if ($this->shouldOpenCreatedObjectsInBrowser()) { | ||||
$this->openURIsInBrowser(array($diff_info['uri'])); | $this->openURIsInBrowser(array($diff_info['uri'])); | ||||
} | } | ||||
} else { | } else { | ||||
$is_draft = $this->getArgument('draft'); | |||||
$revision['diffid'] = $this->getDiffID(); | $revision['diffid'] = $this->getDiffID(); | ||||
if ($commit_message->getRevisionID()) { | 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( | $result = $conduit->callMethodSynchronous( | ||||
'differential.updaterevision', | 'differential.updaterevision', | ||||
$revision); | $revision); | ||||
foreach (array('edit-messages.json', 'update-messages.json') as $file) { | foreach (array('edit-messages.json', 'update-messages.json') as $file) { | ||||
$messages = $this->readScratchJSONFile($file); | $messages = $this->readScratchJSONFile($file); | ||||
unset($messages[$revision['id']]); | unset($messages[$revision['id']]); | ||||
$this->writeScratchJSONFile($file, $messages); | $this->writeScratchJSONFile($file, $messages); | ||||
} | } | ||||
$result_uri = $result['uri']; | |||||
$result_id = $result['revisionid']; | |||||
echo pht('Updated an existing Differential revision:')."\n"; | echo pht('Updated an existing Differential revision:')."\n"; | ||||
} else { | } else { | ||||
// NOTE: We're either using "differential.revision.edit" (preferred) | // NOTE: We're either using "differential.revision.edit" (preferred) | ||||
// if we can, or falling back to "differential.createrevision" | // if we can, or falling back to "differential.createrevision" | ||||
// (the older way) if not. | // (the older way) if not. | ||||
$xactions = $this->revisionTransactions; | $xactions = $this->revisionTransactions; | ||||
if ($xactions) { | if ($xactions) { | ||||
$xactions[] = array( | $xactions[] = array( | ||||
'type' => 'update', | 'type' => 'update', | ||||
'value' => $diff_info['phid'], | 'value' => $diff_info['phid'], | ||||
); | ); | ||||
if ($is_draft) { | |||||
$xactions[] = array( | |||||
'type' => 'draft', | |||||
'value' => true, | |||||
); | |||||
} | |||||
$result = $conduit->callMethodSynchronous( | $result = $conduit->callMethodSynchronous( | ||||
'differential.revision.edit', | 'differential.revision.edit', | ||||
array( | array( | ||||
'transactions' => $xactions, | 'transactions' => $xactions, | ||||
)); | )); | ||||
$result_id = idxv($result, array('object', 'id')); | $result_id = idxv($result, array('object', 'id')); | ||||
if (!$result_id) { | if (!$result_id) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Expected a revision ID to be returned by '. | 'Expected a revision ID to be returned by '. | ||||
'"differential.revision.edit".')); | '"differential.revision.edit".')); | ||||
} | } | ||||
// TODO: This is hacky, but we don't currently receive a URI back | // TODO: This is hacky, but we don't currently receive a URI back | ||||
// from "differential.revision.edit". | // from "differential.revision.edit". | ||||
$result_uri = id(new PhutilURI($this->getConduitURI())) | $result_uri = id(new PhutilURI($this->getConduitURI())) | ||||
->setPath('/D'.$result_id); | ->setPath('/D'.$result_id); | ||||
} else { | } 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.')); | |||||
amckinley: I guess we don't do too much of this in general, and we shouldn't force people to upgrade… | |||||
} | |||||
$revision = $this->dispatchWillCreateRevisionEvent($revision); | $revision = $this->dispatchWillCreateRevisionEvent($revision); | ||||
$result = $conduit->callMethodSynchronous( | $result = $conduit->callMethodSynchronous( | ||||
'differential.createrevision', | 'differential.createrevision', | ||||
$revision); | $revision); | ||||
$result_uri = $result['uri']; | $result_uri = $result['uri']; | ||||
$result_id = $result['revisionid']; | $result_id = $result['revisionid']; | ||||
▲ Show 20 Lines • Show All 2,373 Lines • Show Last 20 Lines |
I guess we don't do too much of this in general, and we shouldn't force people to upgrade unless they're actually going to be using --draft, but I wonder if we should ever build an generic versioned API instead of explicitly doing checks like this.