2013-03-15 12:28:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ReleephBranchCreateController extends ReleephController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$releeph_project = $this->getReleephProject();
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$cut_point = $request->getStr('cutPoint');
|
|
|
|
$symbolic_name = $request->getStr('symbolicName');
|
|
|
|
|
|
|
|
if (!$cut_point) {
|
|
|
|
$repository = $releeph_project->loadPhabricatorRepository();
|
|
|
|
switch ($repository->getVersionControlSystem()) {
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
|
|
|
$cut_point = $releeph_project->getTrunkBranch();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$e_cut = true;
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
$branch_date_control = id(new AphrontFormDateControl())
|
|
|
|
->setUser($request->getUser())
|
|
|
|
->setName('templateDate')
|
2013-05-04 03:33:49 +02:00
|
|
|
->setLabel(pht('Date'))
|
|
|
|
->setCaption(pht('The date used for filling out the branch template.'))
|
2013-03-15 12:28:43 +01:00
|
|
|
->setInitialTime(AphrontFormDateControl::TIME_START_OF_DAY);
|
|
|
|
$branch_date = $branch_date_control->readValueFromRequest($request);
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$cut_commit = null;
|
|
|
|
if (!$cut_point) {
|
2013-05-04 03:33:49 +02:00
|
|
|
$e_cut = pht('Required');
|
|
|
|
$errors[] = pht('You must give a branch cut point');
|
2013-03-15 12:28:43 +01:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$finder = id(new ReleephCommitFinder())
|
2013-05-15 00:32:19 +02:00
|
|
|
->setUser($request->getUser())
|
2013-03-15 12:28:43 +01:00
|
|
|
->setReleephProject($releeph_project);
|
|
|
|
$cut_commit = $finder->fromPartial($cut_point);
|
|
|
|
} catch (Exception $e) {
|
2013-05-04 03:33:49 +02:00
|
|
|
$e_cut = pht('Invalid');
|
2013-03-15 12:28:43 +01:00
|
|
|
$errors[] = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$branch = id(new ReleephBranchEditor())
|
|
|
|
->setReleephProject($releeph_project)
|
|
|
|
->setActor($request->getUser())
|
|
|
|
->newBranchFromCommit(
|
|
|
|
$cut_commit,
|
|
|
|
$branch_date,
|
|
|
|
$symbolic_name);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($branch->getURI());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = array();
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = new AphrontErrorView();
|
|
|
|
$error_view->setErrors($errors);
|
2013-05-04 03:33:49 +02:00
|
|
|
$error_view->setTitle(pht('Form Errors'));
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($request->getUser())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-05-04 03:33:49 +02:00
|
|
|
->setLabel(pht('Symbolic Name'))
|
2013-03-15 12:28:43 +01:00
|
|
|
->setName('symbolicName')
|
|
|
|
->setValue($symbolic_name)
|
2013-05-04 03:33:49 +02:00
|
|
|
->setCaption(pht('Mutable alternate name, for easy reference, '.
|
|
|
|
'(e.g. "LATEST")')))
|
2013-03-15 12:28:43 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-05-04 03:33:49 +02:00
|
|
|
->setLabel(pht('Cut point'))
|
2013-03-15 12:28:43 +01:00
|
|
|
->setName('cutPoint')
|
|
|
|
->setValue($cut_point)
|
|
|
|
->setError($e_cut)
|
|
|
|
->setCaption(
|
2013-05-04 03:33:49 +02:00
|
|
|
pht('A commit ID for your repo type, or a '.
|
|
|
|
'Diffusion ID like "rE123"')))
|
2013-03-15 12:28:43 +01:00
|
|
|
->appendChild($branch_date_control)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-05-04 03:33:49 +02:00
|
|
|
->setValue(pht('Cut Branch'))
|
2013-03-15 12:28:43 +01:00
|
|
|
->addCancelButton($releeph_project->getURI()));
|
|
|
|
|
|
|
|
$panel = id(new AphrontPanelView())
|
|
|
|
->appendChild($form)
|
2013-05-04 03:33:49 +02:00
|
|
|
->setHeader(pht('Cut Branch'))
|
2013-03-15 12:28:43 +01:00
|
|
|
->setWidth(AphrontPanelView::WIDTH_FORM);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array($error_view, $panel),
|
2013-05-04 03:33:49 +02:00
|
|
|
array('title' => pht('Cut new branch')));
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
}
|