Differential D7555 Diff 17124 src/applications/differential/controller/DifferentialRevisionLandController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialRevisionLandController.php
Show All 30 Lines | if (is_subclass_of($this->strategyClass, 'DifferentialLandingStrategy')) { | ||||
throw new Exception( | throw new Exception( | ||||
"Strategy type must be a valid class name and must subclass ". | "Strategy type must be a valid class name and must subclass ". | ||||
"DifferentialLandingStrategy. ". | "DifferentialLandingStrategy. ". | ||||
"'{$this->strategyClass}' is not a subclass of ". | "'{$this->strategyClass}' is not a subclass of ". | ||||
"DifferentialLandingStrategy."); | "DifferentialLandingStrategy."); | ||||
} | } | ||||
if ($request->isDialogFormPost()) { | if ($request->isDialogFormPost()) { | ||||
$response = null; | |||||
$text = ''; | |||||
try { | try { | ||||
$this->attemptLand($revision, $request); | $response = $this->attemptLand($revision, $request); | ||||
$title = pht("Success!"); | $title = pht("Success!"); | ||||
$text = pht("Revision was successfully landed."); | $text = pht("Revision was successfully landed."); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$title = pht("Failed to land revision"); | $title = pht("Failed to land revision"); | ||||
$text = 'moo'; | |||||
epriestley: goodbye moo
you will be missed | |||||
if ($ex instanceof PhutilProxyException) { | if ($ex instanceof PhutilProxyException) { | ||||
$text = hsprintf( | $text = hsprintf( | ||||
'%s:<br><pre>%s</pre>', | '%s:<br><pre>%s</pre>', | ||||
$ex->getMessage(), | $ex->getMessage(), | ||||
$ex->getPreviousException()->getMessage()); | $ex->getPreviousException()->getMessage()); | ||||
} else { | } else { | ||||
$text = phutil_tag('pre', array(), $ex->getMessage()); | $text = phutil_tag('pre', array(), $ex->getMessage()); | ||||
} | } | ||||
$text = id(new AphrontErrorView()) | $text = id(new AphrontErrorView()) | ||||
->appendChild($text); | ->appendChild($text); | ||||
} | } | ||||
if ($response instanceof AphrontDialogView) { | |||||
$dialog = $response; | |||||
} else { | |||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setTitle($title) | ->setTitle($title) | ||||
->appendChild(phutil_tag('p', array(), $text)) | ->appendChild(phutil_tag('p', array(), $text)) | ||||
->setSubmitURI('/D'.$revision_id) | ->addCancelButton('/D'.$revision_id, pht('Done')); | ||||
->addSubmitButton(pht('Done')); | } | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
$prompt = hsprintf('%s<br><br>%s', | $prompt = hsprintf('%s<br><br>%s', | ||||
pht( | pht( | ||||
'This will squash and rebase revision %s, and push it to '. | 'This will squash and rebase revision %s, and push it to '. | ||||
'the default / master branch.', | 'the default / master branch.', | ||||
$revision_id), | $revision_id), | ||||
pht('It is an experimental feature and may not work.')); | pht('It is an experimental feature and may not work.')); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setTitle(pht("Land Revision %s?", $revision_id)) | ->setTitle(pht("Land Revision %s?", $revision_id)) | ||||
->appendChild($prompt) | ->appendChild($prompt) | ||||
->setSubmitURI($request->getRequestURI()) | ->setSubmitURI($request->getRequestURI()) | ||||
->addSubmitButton(pht('Land it!')) | ->addSubmitButton(pht('Land it!')) | ||||
->addCancelButton('/D'.$revision_id); | ->addCancelButton('/D'.$revision_id); | ||||
Not Done Inline Actionsnot sure where this came from. avivey: not sure where this came from. | |||||
Not Done Inline ActionsThis should be pht()'d, but should also be the default button label? epriestley: This should be `pht()`'d, but should also be the default button label? | |||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
private function attemptLand($revision, $request) { | private function attemptLand($revision, $request) { | ||||
$status = $revision->getStatus(); | $status = $revision->getStatus(); | ||||
if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) { | if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) { | ||||
throw new Exception("Only Accepted revisions can be landed."); | throw new Exception("Only Accepted revisions can be landed."); | ||||
Show All 13 Lines | private function attemptLand($revision, $request) { | ||||
if (!$can_push) { | if (!$can_push) { | ||||
throw new Exception( | throw new Exception( | ||||
pht('You do not have permission to push to this repository.')); | pht('You do not have permission to push to this repository.')); | ||||
} | } | ||||
$lock = $this->lockRepository($repository); | $lock = $this->lockRepository($repository); | ||||
try { | try { | ||||
$this->pushStrategy->processLandRequest( | $response = $this->pushStrategy->processLandRequest( | ||||
$request, | $request, | ||||
$revision, | $revision, | ||||
$repository); | $repository); | ||||
} catch (Exception $e) { | } catch (Exception $e) { | ||||
$lock->unlock(); | $lock->unlock(); | ||||
throw $e; | throw $e; | ||||
} | } | ||||
$lock->unlock(); | $lock->unlock(); | ||||
return $response; | |||||
} | } | ||||
private function lockRepository($repository) { | private function lockRepository($repository) { | ||||
$lock_name = __CLASS__.':'.($repository->getCallsign()); | $lock_name = __CLASS__.':'.($repository->getCallsign()); | ||||
$lock = PhabricatorGlobalLock::newLock($lock_name); | $lock = PhabricatorGlobalLock::newLock($lock_name); | ||||
$lock->lock(); | $lock->lock(); | ||||
return $lock; | return $lock; | ||||
} | } | ||||
} | } | ||||
goodbye moo
you will be missed