Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistCloseRevisionWorkflow.php
| Show All 26 Lines | return phutil_console_format(<<<EOTEXT | ||||
| change a revision status from "Accepted" to "Closed". | change a revision status from "Accepted" to "Closed". | ||||
| EOTEXT | EOTEXT | ||||
| ); | ); | ||||
| } | } | ||||
| public function getArguments() { | public function getArguments() { | ||||
| return array( | return array( | ||||
| 'finalize' => array( | 'finalize' => array( | ||||
| 'help' => | 'help' => pht( | ||||
| "Close only if the repository is untracked and the revision is ". | "Close only if the repository is untracked and the revision is ". | ||||
| "accepted. Continue even if the close can't happen. This is a soft ". | "accepted. Continue even if the close can't happen. This is a soft ". | ||||
| "version of 'close-revision' used by other workflows.", | "version of '' used by other workflows.", | ||||
| 'close-revision'), | |||||
| ), | ), | ||||
| 'quiet' => array( | 'quiet' => array( | ||||
| 'help' => 'Do not print a success message.', | 'help' => pht('Do not print a success message.'), | ||||
| ), | ), | ||||
| '*' => 'revision', | '*' => 'revision', | ||||
| ); | ); | ||||
| } | } | ||||
| public function requiresConduit() { | public function requiresConduit() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 13 Lines | EOTEXT | ||||
| public function run() { | public function run() { | ||||
| $is_finalize = $this->getArgument('finalize'); | $is_finalize = $this->getArgument('finalize'); | ||||
| $conduit = $this->getConduit(); | $conduit = $this->getConduit(); | ||||
| $revision_list = $this->getArgument('revision', array()); | $revision_list = $this->getArgument('revision', array()); | ||||
| if (!$revision_list) { | if (!$revision_list) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'close-revision requires a revision number.'); | pht( | ||||
| '%s requires a revision number.', | |||||
| 'close-revision')); | |||||
| } | } | ||||
| if (count($revision_list) != 1) { | if (count($revision_list) != 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'close-revision requires exactly one revision.'); | pht( | ||||
| '%s requires exactly one revision.', | |||||
| 'close-revision')); | |||||
| } | } | ||||
| $revision_id = reset($revision_list); | $revision_id = reset($revision_list); | ||||
| $revision_id = $this->normalizeRevisionID($revision_id); | $revision_id = $this->normalizeRevisionID($revision_id); | ||||
| $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); | ||||
| if (!$revision && !$is_finalize) { | if (!$revision && !$is_finalize) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Revision D{$revision_id} does not exist." | pht( | ||||
| ); | 'Revision %s does not exist.', | ||||
| "D{$revision_id}")); | |||||
| } | } | ||||
| $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( | ||||
| "Revision D{$revision_id} can not be closed. You can only close ". | pht( | ||||
| "revisions which have been 'accepted'."); | "Revision %s can not be closed. You can only close ". | ||||
| "revisions which have been 'accepted'.", | |||||
| "D{$revision_id}")); | |||||
| } | } | ||||
| if ($revision) { | if ($revision) { | ||||
| if (!$is_finalize && $revision['authorPHID'] != $this->getUserPHID()) { | if (!$is_finalize && $revision['authorPHID'] != $this->getUserPHID()) { | ||||
| $prompt = "You are not the author of revision D{$revision_id}, ". | $prompt = pht( | ||||
| 'are you sure you want to close it?'; | 'You are not the author of revision %s, '. | ||||
| 'are you sure you want to close it?', | |||||
| "D{$revision_id}"); | |||||
| 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) { | $revision['status'] != $status_accepted) { | ||||
| $actually_close = false; | $actually_close = false; | ||||
| } | } | ||||
| } | } | ||||
| if ($actually_close) { | if ($actually_close) { | ||||
| $revision_name = $revision['title']; | $revision_name = $revision['title']; | ||||
| echo "Closing revision D{$revision_id} '{$revision_name}'...\n"; | echo pht( | ||||
| "Closing revision %s '%s'...\n", | |||||
| "D{$revision_id}", | |||||
| $revision_name); | |||||
| $conduit->callMethodSynchronous( | $conduit->callMethodSynchronous( | ||||
| 'differential.close', | 'differential.close', | ||||
| array( | array( | ||||
| 'revisionID' => $revision_id, | 'revisionID' => $revision_id, | ||||
| )); | )); | ||||
| } | } | ||||
| } | } | ||||
| $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. | ||||
| $is_finalized = empty($revision['commits']); | $is_finalized = empty($revision['commits']); | ||||
| } else { | } else { | ||||
| $is_finalized = false; | $is_finalized = false; | ||||
| } | } | ||||
| if (!$this->getArgument('quiet')) { | if (!$this->getArgument('quiet')) { | ||||
| if ($is_finalized) { | if ($is_finalized) { | ||||
| $message = $this->getRepositoryAPI()->getFinalizedRevisionMessage(); | $message = $this->getRepositoryAPI()->getFinalizedRevisionMessage(); | ||||
| echo phutil_console_wrap($message)."\n"; | echo phutil_console_wrap($message)."\n"; | ||||
| } else { | } else { | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||