3 final class ReleephRequestEditController
extends ReleephBranchController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $action = $request->getURIData('action');
7 $request_id = $request->getURIData('requestID');
8 $branch_id = $request->getURIData('branchID');
9 $viewer = $request->getViewer();
12 $pull = id(new ReleephRequestQuery())
14 ->withIDs(array($request_id))
15 ->requireCapabilities(
17 PhabricatorPolicyCapability
::CAN_VIEW
,
18 PhabricatorPolicyCapability
::CAN_EDIT
,
22 return new Aphront404Response();
25 $branch = $pull->getBranch();
29 $branch = id(new ReleephBranchQuery())
31 ->withIDs(array($branch_id))
34 return new Aphront404Response();
37 $pull = id(new ReleephRequest())
38 ->setRequestUserPHID($viewer->getPHID())
39 ->setBranchID($branch->getID())
41 ->attachBranch($branch);
45 $this->setBranch($branch);
47 $product = $branch->getProduct();
49 $request_identifier = $request->getStr('requestIdentifierRaw');
50 $e_request_identifier = true;
52 // Load all the ReleephFieldSpecifications
53 $selector = $branch->getProduct()->getReleephFieldSelector();
54 $fields = $selector->getFieldSpecifications();
55 foreach ($fields as $field) {
57 ->setReleephProject($product)
58 ->setReleephBranch($branch)
59 ->setReleephRequest($pull);
62 $field_list = PhabricatorCustomField
::getObjectFields(
64 PhabricatorCustomField
::ROLE_EDIT
);
65 foreach ($field_list->getFields() as $field) {
67 ->setReleephProject($product)
68 ->setReleephBranch($branch)
69 ->setReleephRequest($pull);
71 $field_list->readFieldsFromStorage($pull);
75 $cancel_uri = $this->getApplicationURI('branch/'.$branch_id.'/');
77 $cancel_uri = '/'.$pull->getMonogram();
82 if ($request->isFormPost()) {
85 // The commit-identifier being requested...
87 if ($request_identifier ===
88 ReleephRequestTypeaheadControl
::PLACEHOLDER
) {
90 $errors[] = pht('No commit ID was provided.');
91 $e_request_identifier = pht('Required');
94 $finder = id(new ReleephCommitFinder())
96 ->setReleephProject($product);
98 $pr_commit = $finder->fromPartial($request_identifier);
99 } catch (Exception
$e) {
100 $e_request_identifier = pht('Invalid');
102 'Request %s is probably not a valid commit.',
103 $request_identifier);
104 $errors[] = $e->getMessage();
108 $object_phid = $finder->getRequestedObjectPHID();
110 $object_phid = $pr_commit->getPHID();
113 $pull->setRequestedObjectPHID($object_phid);
118 $existing = id(new ReleephRequest())
119 ->loadOneWhere('requestCommitPHID = %s AND branchID = %d',
120 $pr_commit->getPHID(), $branch->getID());
122 return id(new AphrontRedirectResponse())
123 ->setURI('/releeph/request/edit/'.$existing->getID().
127 $xactions[] = id(new ReleephRequestTransaction())
128 ->setTransactionType(ReleephRequestTransaction
::TYPE_REQUEST
)
129 ->setNewValue($pr_commit->getPHID());
131 $xactions[] = id(new ReleephRequestTransaction())
132 ->setTransactionType(ReleephRequestTransaction
::TYPE_USER_INTENT
)
133 // To help hide these implicit intents...
134 ->setMetadataValue('isRQCreate', true)
135 ->setMetadataValue('userPHID', $viewer->getPHID())
138 $product->isAuthoritative($viewer))
139 ->setNewValue(ReleephRequest
::INTENT_WANT
);
143 // TODO: This should happen implicitly while building transactions
145 foreach ($field_list->getFields() as $field) {
146 $field->readValueFromRequest($request);
150 foreach ($fields as $field) {
151 if ($field->isEditable()) {
153 $data = $request->getRequestData();
154 $value = idx($data, $field->getRequiredStorageKey());
155 $field->validate($value);
156 $xactions[] = id(new ReleephRequestTransaction())
157 ->setTransactionType(ReleephRequestTransaction
::TYPE_EDIT_FIELD
)
158 ->setMetadataValue('fieldClass', get_class($field))
159 ->setNewValue($value);
160 } catch (ReleephFieldParseException
$ex) {
161 $errors[] = $ex->getMessage();
168 $editor = id(new ReleephRequestTransactionalEditor())
170 ->setContinueOnNoEffect(true)
171 ->setContentSourceFromRequest($request);
172 $editor->applyTransactions($pull, $xactions);
173 return id(new AphrontRedirectResponse())->setURI($cancel_uri);
177 $handle_phids = array(
178 $pull->getRequestUserPHID(),
179 $pull->getRequestCommitPHID(),
181 $handle_phids = array_filter($handle_phids);
183 $handles = id(new PhabricatorHandleQuery())
185 ->withPHIDs($handle_phids)
193 $age_string = phutil_format_relative_time(
194 time() - $pull->getDateCreated()).' ago';
197 // Warn the user if we've been redirected here because we tried to
198 // re-request something.
200 if ($request->getInt('existing')) {
201 $notice_messages = array(
202 pht('You are editing an existing pick request!'),
204 'Requested %s by %s',
206 $handles[$pull->getRequestUserPHID()]->renderLink()),
208 $notice_view = id(new PHUIInfoView())
209 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
210 ->setErrors($notice_messages);
213 $form = id(new AphrontFormView())
219 id(new AphrontFormMarkupControl())
220 ->setLabel(pht('Original Commit'))
222 $handles[$pull->getRequestCommitPHID()]->renderLink()))
224 id(new AphrontFormMarkupControl())
225 ->setLabel(pht('Requestor'))
228 $handles[$pull->getRequestUserPHID()]->renderLink(),
232 $diff_rev_id = $request->getStr('D');
234 $diff_rev = id(new DifferentialRevisionQuery())
236 ->withIDs(array($diff_rev_id))
238 $origin = '/D'.$diff_rev->getID();
242 $diff_rev->getTitle());
244 ->addHiddenInput('requestIdentifierRaw', 'D'.$diff_rev_id)
246 id(new AphrontFormStaticControl())
247 ->setLabel(pht('Diff'))
250 $origin = $branch->getURI();
251 $repo = $product->getRepository();
252 $branch_cut_point = id(new PhabricatorRepositoryCommit())
255 $branch->getCutPointCommitPHID());
257 id(new ReleephRequestTypeaheadControl())
258 ->setName('requestIdentifierRaw')
259 ->setLabel(pht('Commit ID'))
261 ->setValue($request_identifier)
262 ->setError($e_request_identifier)
263 ->setStartTime($branch_cut_point->getEpoch())
266 'Start typing to autocomplete on commit title, '.
267 'or give a Phabricator commit identifier like rFOO1234.')));
271 $field_list->appendFieldsToForm($form);
273 $crumbs = $this->buildApplicationCrumbs();
276 $title = pht('Edit Pull Request');
277 $submit_name = pht('Save');
278 $header_icon = 'fa-pencil';
280 $crumbs->addTextCrumb($pull->getMonogram(), '/'.$pull->getMonogram());
281 $crumbs->addTextCrumb(pht('Edit'));
283 $title = pht('Create Pull Request');
284 $submit_name = pht('Create Pull Request');
285 $header_icon = 'fa-plus-square';
287 $crumbs->addTextCrumb(pht('New Pull Request'));
291 id(new AphrontFormSubmitControl())
292 ->addCancelButton($cancel_uri, pht('Cancel'))
293 ->setValue($submit_name));
295 $box = id(new PHUIObjectBoxView())
296 ->setHeaderText(pht('Request'))
297 ->setFormErrors($errors)
298 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
299 ->appendChild($form);
301 $crumbs->setBorder(true);
303 $header = id(new PHUIHeaderView())
305 ->setHeaderIcon($header_icon);
307 $view = id(new PHUITwoColumnView())
314 return $this->newPage()
317 ->appendChild($view);