mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
eccbbce9a2
Summary: Now that diffs have PHIDs we can create buildables for them. This also adds `buildable.diff` in the variables list so the diff ID is available, and it also fixes the Cancel button on "Edit Plan" page so it redirects to the right place. Test Plan: Created a buildable from a diff, ran a build plan against it that had `echo ${buildable.diff}` and got the right ID. Also tested the "Edit Plan" cancel redirect. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T1049 Differential Revision: https://secure.phabricator.com/D7546
147 lines
3.9 KiB
PHP
147 lines
3.9 KiB
PHP
<?php
|
|
|
|
final class HarbormasterBuildableEditController
|
|
extends HarbormasterController {
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = idx($data, 'id');
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$viewer = $request->getUser();
|
|
|
|
$this->requireApplicationCapability(
|
|
HarbormasterCapabilityManagePlans::CAPABILITY);
|
|
|
|
if ($this->id) {
|
|
$buildable = id(new HarbormasterBuildableQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($this->id))
|
|
->executeOne();
|
|
if (!$buildable) {
|
|
return new Aphront404Response();
|
|
}
|
|
} else {
|
|
$buildable = HarbormasterBuildable::initializeNewBuildable($viewer);
|
|
}
|
|
|
|
$e_name = true;
|
|
$v_name = null;
|
|
|
|
$errors = array();
|
|
if ($request->isFormPost()) {
|
|
$v_name = $request->getStr('buildablePHID');
|
|
|
|
if ($v_name) {
|
|
$object = id(new PhabricatorObjectQuery())
|
|
->setViewer($viewer)
|
|
->withNames(array($v_name))
|
|
->executeOne();
|
|
|
|
if ($object instanceof DifferentialRevision) {
|
|
$revision = $object;
|
|
$object = $object->loadActiveDiff();
|
|
$buildable
|
|
->setBuildablePHID($object->getPHID())
|
|
->setContainerPHID($revision->getPHID());
|
|
} else if ($object instanceof PhabricatorRepositoryCommit) {
|
|
$buildable
|
|
->setBuildablePHID($object->getPHID())
|
|
->setContainerPHID($object->getRepository()->getPHID());
|
|
} else {
|
|
$e_name = pht('Invalid');
|
|
$errors[] = pht('Enter the name of a revision or commit.');
|
|
}
|
|
} else {
|
|
$e_name = pht('Required');
|
|
$errors[] = pht('You must choose a revision or commit to build.');
|
|
}
|
|
|
|
if (!$errors) {
|
|
$buildable->save();
|
|
|
|
$buildable_uri = '/B'.$buildable->getID();
|
|
return id(new AphrontRedirectResponse())->setURI($buildable_uri);
|
|
}
|
|
}
|
|
|
|
if ($errors) {
|
|
$errors = id(new AphrontErrorView())->setErrors($errors);
|
|
}
|
|
|
|
$is_new = (!$buildable->getID());
|
|
if ($is_new) {
|
|
$title = pht('New Buildable');
|
|
$cancel_uri = $this->getApplicationURI();
|
|
$save_button = pht('Create Buildable');
|
|
} else {
|
|
$id = $buildable->getID();
|
|
|
|
$title = pht('Edit Buildable');
|
|
$cancel_uri = "/B{$id}";
|
|
$save_button = pht('Save Buildable');
|
|
}
|
|
|
|
$form = id(new AphrontFormView())
|
|
->setUser($viewer);
|
|
|
|
if ($is_new) {
|
|
$form
|
|
->appendRemarkupInstructions(
|
|
pht(
|
|
'Enter the name of a commit or revision, like `rX123456789` '.
|
|
'or `D123`.'))
|
|
->appendChild(
|
|
id(new AphrontFormTextControl())
|
|
->setLabel('Buildable Name')
|
|
->setName('buildablePHID')
|
|
->setError($e_name)
|
|
->setValue($v_name));
|
|
} else {
|
|
$form->appendChild(
|
|
id(new AphrontFormMarkupControl())
|
|
->setLabel(pht('Buildable'))
|
|
->setValue($buildable->getBuildableHandle()->renderLink()));
|
|
}
|
|
|
|
$form->appendChild(
|
|
id(new AphrontFormSubmitControl())
|
|
->setValue($save_button)
|
|
->addCancelButton($cancel_uri));
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
->setHeaderText($title)
|
|
->setFormError($errors)
|
|
->setForm($form);
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
if ($is_new) {
|
|
$crumbs->addCrumb(
|
|
id(new PhabricatorCrumbView())
|
|
->setName(pht('New Buildable')));
|
|
} else {
|
|
$id = $buildable->getID();
|
|
$crumbs->addCrumb(
|
|
id(new PhabricatorCrumbView())
|
|
->setName("B{$id}")
|
|
->setHref("/B{$id}"));
|
|
$crumbs->addCrumb(
|
|
id(new PhabricatorCrumbView())
|
|
->setName(pht('Edit')));
|
|
}
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$box,
|
|
),
|
|
array(
|
|
'title' => $title,
|
|
'device' => true,
|
|
));
|
|
}
|
|
|
|
}
|