Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistCloseRevisionWorkflow.php
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | public function run() { | ||||
$revisions = $conduit->callMethodSynchronous( | $revisions = $conduit->callMethodSynchronous( | ||||
'differential.query', | 'differential.query', | ||||
array( | array( | ||||
'ids' => array($revision_id), | 'ids' => array($revision_id), | ||||
)); | )); | ||||
$revision = head($revisions); | $revision = head($revisions); | ||||
$object_name = "D{$revision_id}"; | |||||
if (!$revision && !$is_finalize) { | if (!$revision && !$is_finalize) { | ||||
throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
pht( | pht( | ||||
'Revision %s does not exist.', | 'Revision %s does not exist.', | ||||
"D{$revision_id}")); | $object_name)); | ||||
} | } | ||||
$status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; | $status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; | ||||
$status_closed = ArcanistDifferentialRevisionStatus::CLOSED; | $status_closed = ArcanistDifferentialRevisionStatus::CLOSED; | ||||
if (!$is_finalize && $revision['status'] != $status_accepted) { | if (!$is_finalize && $revision['status'] != $status_accepted) { | ||||
throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
pht( | pht( | ||||
"Revision %s can not be closed. You can only close ". | "Revision %s can not be closed. You can only close ". | ||||
"revisions which have been 'accepted'.", | "revisions which have been 'accepted'.", | ||||
"D{$revision_id}")); | $object_name)); | ||||
} | } | ||||
if ($revision) { | if ($revision) { | ||||
$revision_display = sprintf( | |||||
'%s %s', | |||||
$object_name, | |||||
$revision['title']); | |||||
if (!$is_finalize && $revision['authorPHID'] != $this->getUserPHID()) { | if (!$is_finalize && $revision['authorPHID'] != $this->getUserPHID()) { | ||||
$prompt = pht( | $prompt = pht( | ||||
'You are not the author of revision %s, '. | 'You are not the author of revision "%s", '. | ||||
'are you sure you want to close it?', | 'are you sure you want to close it?', | ||||
"D{$revision_id}"); | $object_name); | ||||
if (!phutil_console_confirm($prompt)) { | if (!phutil_console_confirm($prompt)) { | ||||
throw new ArcanistUserAbortException(); | throw new ArcanistUserAbortException(); | ||||
} | } | ||||
} | } | ||||
$actually_close = true; | $actually_close = true; | ||||
if ($is_finalize) { | if ($is_finalize) { | ||||
if ($this->getRepositoryPHID() || | if ($this->getRepositoryPHID()) { | ||||
$revision['status'] != $status_accepted) { | $actually_close = false; | ||||
} else if ($revision['status'] != $status_accepted) { | |||||
// See T13458. The server doesn't permit a transition to "Closed" | |||||
// over the API if the revision is not "Accepted". If we won't be | |||||
// able to close the revision, skip the attempt and print a | |||||
// message. | |||||
$this->writeWarn( | |||||
pht('OPEN REVISION'), | |||||
pht( | |||||
'Revision "%s" is not in state "Accepted", so it will '. | |||||
'be left open.', | |||||
$object_name)); | |||||
$actually_close = false; | $actually_close = false; | ||||
} | } | ||||
} | } | ||||
if ($actually_close) { | |||||
$revision_name = $revision['title']; | |||||
echo pht( | if ($actually_close) { | ||||
"Closing revision %s '%s'...\n", | $this->writeInfo( | ||||
"D{$revision_id}", | pht('CLOSE'), | ||||
$revision_name); | pht( | ||||
'Closing revision "%s"...', | |||||
$revision_display)); | |||||
$conduit->callMethodSynchronous( | $conduit->callMethodSynchronous( | ||||
'differential.close', | 'differential.close', | ||||
array( | array( | ||||
'revisionID' => $revision_id, | 'revisionID' => $revision_id, | ||||
)); | )); | ||||
$this->writeOkay( | |||||
pht('CLOSE'), | |||||
pht( | |||||
'Done, closed revision.')); | |||||
} | } | ||||
} | } | ||||
$status = $revision['status']; | $status = $revision['status']; | ||||
if ($status == $status_accepted || $status == $status_closed) { | if ($status == $status_accepted || $status == $status_closed) { | ||||
// If this has already been attached to commits, don't show the | // If this has already been attached to commits, don't show the | ||||
// "you can push this commit" message since we know it's been pushed | // "you can push this commit" message since we know it's been pushed | ||||
// already. | // already. | ||||
Show All 18 Lines |