Differential D14733 Diff 35633 src/applications/differential/controller/DifferentialRevisionOperationController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialRevisionOperationController.php
| Show All 21 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| $barrier = $op->getBarrierToLanding($viewer, $revision); | $barrier = $op->getBarrierToLanding($viewer, $revision); | ||||
| if ($barrier) { | if ($barrier) { | ||||
| return $this->newDialog() | return $this->newDialog() | ||||
| ->setTitle($barrier['title']) | ->setTitle($barrier['title']) | ||||
| ->appendParagraph($barrier['body']) | ->appendParagraph($barrier['body']) | ||||
| ->addCancelButton($detail_uri); | ->addCancelButton($detail_uri); | ||||
| } | } | ||||
| $diff = $revision->getActiveDiff(); | |||||
| $repository = $revision->getRepository(); | |||||
| $ref_types = array( | |||||
| PhabricatorRepositoryRefCursor::TYPE_BRANCH, | |||||
| ); | |||||
| $e_ref = true; | |||||
| $errors = array(); | |||||
| if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
| $ref_phid = head($request->getArr('refPHIDs')); | |||||
| if (!strlen($ref_phid)) { | |||||
| $e_ref = pht('Required'); | |||||
| $errors[] = pht( | |||||
| 'You must select a branch to land this revision onto.'); | |||||
| } else { | |||||
| $ref = id(new PhabricatorRepositoryRefCursorQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs(array($ref_phid)) | |||||
| ->withRepositoryPHIDs(array($repository->getPHID())) | |||||
| ->withRefTypes($ref_types) | |||||
| ->executeOne(); | |||||
| if (!$ref) { | |||||
| $e_ref = pht('Invalid'); | |||||
| $errors[] = pht( | |||||
| 'You must select a branch from this repository to land this '. | |||||
| 'revision onto.'); | |||||
| } | |||||
| } | |||||
| if (!$errors) { | |||||
| // NOTE: The operation is locked to the current active diff, so if the | // NOTE: The operation is locked to the current active diff, so if the | ||||
| // revision is updated before the operation applies nothing sneaky | // revision is updated before the operation applies nothing sneaky | ||||
| // occurs. | // occurs. | ||||
| $diff = $revision->getActiveDiff(); | $target = 'branch:'.$ref->getRefName(); | ||||
| $repository = $revision->getRepository(); | |||||
| $operation = DrydockRepositoryOperation::initializeNewOperation($op) | $operation = DrydockRepositoryOperation::initializeNewOperation($op) | ||||
| ->setAuthorPHID($viewer->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
| ->setObjectPHID($revision->getPHID()) | ->setObjectPHID($revision->getPHID()) | ||||
| ->setRepositoryPHID($repository->getPHID()) | ->setRepositoryPHID($repository->getPHID()) | ||||
| ->setRepositoryTarget('branch:master') | ->setRepositoryTarget($target) | ||||
| ->setProperty('differential.diffPHID', $diff->getPHID()); | ->setProperty('differential.diffPHID', $diff->getPHID()); | ||||
| $operation->save(); | $operation->save(); | ||||
| $operation->scheduleUpdate(); | $operation->scheduleUpdate(); | ||||
| return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
| ->setURI($detail_uri); | ->setURI($detail_uri); | ||||
| } | } | ||||
| } | |||||
| return $this->newDialog() | $ref_datasource = id(new DiffusionRefDatasource()) | ||||
| ->setTitle(pht('Land Revision')) | ->setParameters( | ||||
| ->appendParagraph( | array( | ||||
| 'repositoryPHIDs' => array($repository->getPHID()), | |||||
| 'refTypes' => $ref_types, | |||||
| )); | |||||
| $form = id(new AphrontFormView()) | |||||
| ->setUser($viewer) | |||||
| ->appendRemarkupInstructions( | |||||
| pht( | pht( | ||||
| 'In theory, this will do approximately what `arc land` would do. '. | 'In theory, this will do approximately what `arc land` would do. '. | ||||
| 'In practice, that is almost certainly not what it will actually '. | 'In practice, you will have a riveting adventure instead.')) | ||||
| 'do.')) | ->appendControl( | ||||
| ->appendParagraph( | id(new AphrontFormTokenizerControl()) | ||||
| ->setLabel(pht('Onto Branch')) | |||||
| ->setName('refPHIDs') | |||||
| ->setLimit(1) | |||||
| ->setError($e_ref) | |||||
| ->setDatasource($ref_datasource)) | |||||
| ->appendRemarkupInstructions( | |||||
| pht( | pht( | ||||
| 'THIS FEATURE IS EXPERIMENTAL AND DANGEROUS! USE IT AT YOUR '. | '(WARNING) THIS FEATURE IS EXPERIMENTAL AND DANGEROUS! USE IT AT '. | ||||
| 'OWN RISK!')) | 'YOUR OWN RISK!')); | ||||
| return $this->newDialog() | |||||
| ->setWidth(AphrontDialogView::WIDTH_FORM) | |||||
| ->setTitle(pht('Land Revision')) | |||||
| ->setErrors($errors) | |||||
| ->appendForm($form) | |||||
| ->addCancelButton($detail_uri) | ->addCancelButton($detail_uri) | ||||
| ->addSubmitButton(pht('Mutate Repository Unpredictably')); | ->addSubmitButton(pht('Mutate Repository Unpredictably')); | ||||
| } | } | ||||
| } | } | ||||