protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $id = $request->getValue('revisionID'); $revision = id(new DifferentialRevisionQuery())->withIDs(array($id))->setViewer($viewer)->needReviewerStatus(true)->executeOne(); if (!$revision) { throw new ConduitException('ERR_NOT_FOUND'); } $xactions = array(); $xactions[] = id(new DifferentialTransaction())->setTransactionType(DifferentialTransaction::TYPE_ACTION)->setNewValue(DifferentialAction::ACTION_CLOSE); $content_source = $request->newContentSource(); $editor = id(new DifferentialTransactionEditor())->setActor($viewer)->setContentSource($request->newContentSource())->setContinueOnMissingFields(true)->setContinueOnNoEffect(true); $editor->applyTransactions($revision, $xactions); return; }
protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($request->getValue('revision_id')))->needReviewerStatus(true)->needReviewerAuthority(true)->executeOne(); if (!$revision) { throw new ConduitException('ERR_BAD_REVISION'); } $xactions = array(); $action = $request->getValue('action'); if ($action && $action != 'comment' && $action != 'none') { $xactions[] = id(new DifferentialTransaction())->setTransactionType(DifferentialTransaction::TYPE_ACTION)->setNewValue($action); } $content = $request->getValue('message'); if (strlen($content)) { $xactions[] = id(new DifferentialTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new DifferentialTransactionComment())->setContent($content)); } if ($request->getValue('attach_inlines')) { $type_inline = DifferentialTransaction::TYPE_INLINE; $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments($viewer, $revision); foreach ($inlines as $inline) { $xactions[] = id(new DifferentialTransaction())->setTransactionType($type_inline)->attachComment($inline); } } $editor = id(new DifferentialTransactionEditor())->setActor($viewer)->setDisableEmail($request->getValue('silent'))->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true); $editor->applyTransactions($revision, $xactions); return array('revisionid' => $revision->getID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID())); }
protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $raw_diff = $request->getValue('diff'); $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne(); if (!$repository) { throw new Exception(pht('No such repository "%s"!', $repository_phid)); } } $parser = new ArcanistDiffParser(); $changes = $parser->parseDiff($raw_diff); $diff = DifferentialDiff::newFromRawChanges($viewer, $changes); // We're bounded by doing INSERTs for all the hunks and changesets, so // estimate the number of inserts we'll require. $size = 0; foreach ($diff->getChangesets() as $changeset) { $hunks = $changeset->getHunks(); $size += 1 + count($hunks); } $raw_limit = 10000; if ($size > $raw_limit) { throw new Exception(pht('The raw diff you have submitted is too large to parse (it affects ' . 'more than %s paths and hunks). Differential should only be used ' . 'for changes which are small enough to receive detailed human ' . 'review. See "Differential User Guide: Large Changes" in the ' . 'documentation for more information.', new PhutilNumber($raw_limit))); } $diff_data_dict = array('creationMethod' => 'web', 'authorPHID' => $viewer->getPHID(), 'repositoryPHID' => $repository_phid, 'lintStatus' => DifferentialLintStatus::LINT_SKIP, 'unitStatus' => DifferentialUnitStatus::UNIT_SKIP); $xactions = array(id(new DifferentialDiffTransaction())->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)->setNewValue($diff_data_dict)); if ($request->getValue('viewPolicy')) { $xactions[] = id(new DifferentialDiffTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getValue('viewPolicy')); } id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setLookupRepository(false)->applyTransactions($diff, $xactions); return $this->buildDiffInfoDictionary($diff); }
protected function execute(ConduitAPIRequest $request) { $commit_phid = $request->getValue('phid'); $commit = id(new DiffusionCommitQuery())->setViewer($request->getUser())->withPHIDs(array($commit_phid))->needAuditRequests(true)->executeOne(); if (!$commit) { throw new ConduitException('ERR_BAD_COMMIT'); } $message = trim($request->getValue('message')); if (!$message) { throw new ConduitException('ERR_MISSING_MESSAGE'); } $action = $request->getValue('action'); if (!$action) { $action = PhabricatorAuditActionConstants::COMMENT; } // Disallow ADD_CCS, ADD_AUDITORS forever. if (!in_array($action, array(PhabricatorAuditActionConstants::CONCERN, PhabricatorAuditActionConstants::ACCEPT, PhabricatorAuditActionConstants::COMMENT, PhabricatorAuditActionConstants::RESIGN, PhabricatorAuditActionConstants::CLOSE))) { throw new ConduitException('ERR_BAD_ACTION'); } $xactions = array(); if ($action != PhabricatorAuditActionConstants::COMMENT) { $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorAuditActionConstants::ACTION)->setNewValue($action); } if (strlen($message)) { $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new PhabricatorAuditTransactionComment())->setCommitPHID($commit->getPHID())->setContent($message)); } id(new PhabricatorAuditEditor())->setActor($request->getUser())->setContentSource($request->newContentSource())->setDisableEmail($request->getValue('silent'))->setContinueOnMissingFields(true)->applyTransactions($commit, $xactions); return true; }
protected function execute(ConduitAPIRequest $request) { $content_source = $request->newContentSource(); $editor = id(new PhabricatorTokenGivenEditor())->setActor($request->getUser())->setContentSource($content_source); if ($request->getValue('tokenPHID')) { $editor->addToken($request->getValue('objectPHID'), $request->getValue('tokenPHID')); } else { $editor->deleteToken($request->getValue('objectPHID')); } }
protected function execute(ConduitAPIRequest $request) { $action = $request->getValue('action'); $new_commit_id = $request->getValue('commitIdentifier'); $releeph_request = id(new ReleephRequest())->loadOneWhere('phid = %s', $request->getValue('requestPHID')); $xactions = array(); $xactions[] = id(new ReleephRequestTransaction())->setTransactionType(ReleephRequestTransaction::TYPE_COMMIT)->setMetadataValue('action', $action)->setNewValue($new_commit_id); $editor = id(new ReleephRequestTransactionalEditor())->setActor($request->getUser())->setContinueOnNoEffect(true)->setContentSource($request->newContentSource()); $editor->applyTransactions($releeph_request, $xactions); }
protected function execute(ConduitAPIRequest $request) { $user = $request->getUser(); $id = $request->getValue('id'); $phid = $request->getValue('phid'); $query = id(new ConpherenceThreadQuery())->setViewer($user); if ($id) { $query->withIDs(array($id)); } else { if ($phid) { $query->withPHIDs(array($phid)); } else { throw new ConduitException('ERR_USAGE_NO_ROOM_ID'); } } $conpherence = $query->executeOne(); if (!$conpherence) { throw new ConduitException('ERR_USAGE_ROOM_NOT_FOUND'); } $source = $request->newContentSource(); $editor = id(new ConpherenceEditor())->setContentSource($source)->setActor($user); $xactions = array(); $add_participant_phids = $request->getValue('addParticipantPHIDs', array()); $remove_participant_phid = $request->getValue('removeParticipantPHID'); $message = $request->getValue('message'); $title = $request->getValue('title'); if ($add_participant_phids) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $add_participant_phids)); } if ($remove_participant_phid) { if ($remove_participant_phid != $user->getPHID()) { throw new ConduitException('ERR_USAGE_ONLY_SELF_REMOVE'); } $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('-' => array($remove_participant_phid))); } if ($title) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($title); } if ($message) { $xactions = array_merge($xactions, $editor->generateTransactionsFromText($user, $conpherence, $message)); } try { $xactions = $editor->applyTransactions($conpherence, $xactions); } catch (PhabricatorApplicationTransactionNoEffectException $ex) { throw new ConduitException('ERR_USAGE_NO_UPDATES'); } return true; }
protected function execute(ConduitAPIRequest $request) { $slug = $request->getValue('slug'); $doc = id(new PhrictionDocumentQuery())->setViewer($request->getUser())->withSlugs(array(PhabricatorSlug::normalize($slug)))->needContent(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$doc) { throw new Exception(pht('No such document.')); } $xactions = array(); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhrictionTransaction::TYPE_TITLE)->setNewValue($request->getValue('title')); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhrictionTransaction::TYPE_CONTENT)->setNewValue($request->getValue('content')); $editor = id(new PhrictionTransactionEditor())->setActor($request->getUser())->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setDescription($request->getValue('description')); try { $editor->applyTransactions($doc, $xactions); } catch (PhabricatorApplicationTransactionValidationException $ex) { // TODO - some magical hotness via T5873 throw $ex; } return $this->buildDocumentInfoDictionary($doc); }
protected function execute(ConduitAPIRequest $request) { $participant_phids = $request->getValue('participantPHIDs', array()); $message = $request->getValue('message'); $title = $request->getValue('title'); list($errors, $conpherence) = ConpherenceEditor::createThread($request->getUser(), $participant_phids, $title, $message, $request->newContentSource()); if ($errors) { foreach ($errors as $error_code) { switch ($error_code) { case ConpherenceEditor::ERROR_EMPTY_MESSAGE: throw new ConduitException('ERR_EMPTY_MESSAGE'); break; case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS: throw new ConduitException('ERR_EMPTY_PARTICIPANT_PHIDS'); break; } } } return array('conpherenceID' => $conpherence->getID(), 'conpherencePHID' => $conpherence->getPHID(), 'conpherenceURI' => $this->getConpherenceURI($conpherence)); }
protected function execute(ConduitAPIRequest $request) { $content = $request->getValue('content'); $title = $request->getValue('title'); $language = $request->getValue('language'); if (!strlen($content)) { throw new ConduitException('ERR-NO-PASTE'); } $title = nonempty($title, pht('Masterwork From Distant Lands')); $language = nonempty($language, ''); $viewer = $request->getUser(); $paste = PhabricatorPaste::initializeNewPaste($viewer); $xactions = array(); $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteContentTransaction::TRANSACTIONTYPE)->setNewValue($content); $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)->setNewValue($title); $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)->setNewValue($language); $editor = id(new PhabricatorPasteEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSource($request->newContentSource()); $xactions = $editor->applyTransactions($paste, $xactions); $paste->attachRawContent($content); return $this->buildPasteInfoDictionary($paste); }
protected function execute(ConduitAPIRequest $request) { $action = $request->getValue('action'); $ok = $request->getValue('ok'); $dry_run = $request->getValue('dryRun'); $details = $request->getValue('details', array()); switch ($request->getValue('action')) { case 'pick': $pick_status = $ok ? ReleephRequest::PICK_OK : ReleephRequest::PICK_FAILED; break; case 'revert': $pick_status = $ok ? ReleephRequest::REVERT_OK : ReleephRequest::REVERT_FAILED; break; default: throw new Exception(pht('Unknown action %s!', $action)); } $releeph_request = id(new ReleephRequest())->loadOneWhere('phid = %s', $request->getValue('requestPHID')); $editor = id(new ReleephRequestTransactionalEditor())->setActor($request->getUser())->setContinueOnNoEffect(true)->setContentSource($request->newContentSource()); $xactions = array(); $xactions[] = id(new ReleephRequestTransaction())->setTransactionType(ReleephRequestTransaction::TYPE_PICK_STATUS)->setMetadataValue('dryRun', $dry_run)->setMetadataValue('details', $details)->setNewValue($pick_status); $editor->applyTransactions($releeph_request, $xactions); }
protected function applyRequest(ManiphestTask $task, ConduitAPIRequest $request, $is_new) { $changes = array(); if ($is_new) { $task->setTitle((string) $request->getValue('title')); $task->setDescription((string) $request->getValue('description')); $changes[ManiphestTransaction::TYPE_STATUS] = ManiphestTaskStatus::getDefaultStatus(); $changes[PhabricatorTransactions::TYPE_SUBSCRIBERS] = array('+' => array($request->getUser()->getPHID())); } else { $comments = $request->getValue('comments'); if (!$is_new && $comments !== null) { $changes[PhabricatorTransactions::TYPE_COMMENT] = null; } $title = $request->getValue('title'); if ($title !== null) { $changes[ManiphestTransaction::TYPE_TITLE] = $title; } $desc = $request->getValue('description'); if ($desc !== null) { $changes[ManiphestTransaction::TYPE_DESCRIPTION] = $desc; } $status = $request->getValue('status'); if ($status !== null) { $valid_statuses = ManiphestTaskStatus::getTaskStatusMap(); if (!isset($valid_statuses[$status])) { throw id(new ConduitException('ERR-INVALID-PARAMETER'))->setErrorDescription(pht('Status set to invalid value.')); } $changes[ManiphestTransaction::TYPE_STATUS] = $status; } } $priority = $request->getValue('priority'); if ($priority !== null) { $valid_priorities = ManiphestTaskPriority::getTaskPriorityMap(); if (!isset($valid_priorities[$priority])) { throw id(new ConduitException('ERR-INVALID-PARAMETER'))->setErrorDescription(pht('Priority set to invalid value.')); } $changes[ManiphestTransaction::TYPE_PRIORITY] = $priority; } $owner_phid = $request->getValue('ownerPHID'); if ($owner_phid !== null) { $this->validatePHIDList(array($owner_phid), PhabricatorPeopleUserPHIDType::TYPECONST, 'ownerPHID'); $changes[ManiphestTransaction::TYPE_OWNER] = $owner_phid; } $ccs = $request->getValue('ccPHIDs'); if ($ccs !== null) { $changes[PhabricatorTransactions::TYPE_SUBSCRIBERS] = array('=' => array_fuse($ccs)); } $transactions = array(); $view_policy = $request->getValue('viewPolicy'); if ($view_policy !== null) { $transactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($view_policy); } $edit_policy = $request->getValue('editPolicy'); if ($edit_policy !== null) { $transactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($edit_policy); } $project_phids = $request->getValue('projectPHIDs'); if ($project_phids !== null) { $this->validatePHIDList($project_phids, PhabricatorProjectProjectPHIDType::TYPECONST, 'projectPHIDS'); $project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $transactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $project_type)->setNewValue(array('=' => array_fuse($project_phids))); } $template = new ManiphestTransaction(); foreach ($changes as $type => $value) { $transaction = clone $template; $transaction->setTransactionType($type); if ($type == PhabricatorTransactions::TYPE_COMMENT) { $transaction->attachComment(id(new ManiphestTransactionComment())->setContent($comments)); } else { $transaction->setNewValue($value); } $transactions[] = $transaction; } $field_list = PhabricatorCustomField::getObjectFields($task, PhabricatorCustomField::ROLE_EDIT); $field_list->readFieldsFromStorage($task); $auxiliary = $request->getValue('auxiliary'); if ($auxiliary) { foreach ($field_list->getFields() as $key => $field) { if (!array_key_exists($key, $auxiliary)) { continue; } $transaction = clone $template; $transaction->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD); $transaction->setMetadataValue('customfield:key', $key); $transaction->setOldValue($field->getOldValueForApplicationTransactions()); $transaction->setNewValue($auxiliary[$key]); $transactions[] = $transaction; } } if (!$transactions) { return; } $content_source = $request->newContentSource(); $editor = id(new ManiphestTransactionEditor())->setActor($request->getUser())->setContentSource($content_source)->setContinueOnNoEffect(true); if (!$is_new) { $editor->setContinueOnMissingFields(true); } $editor->applyTransactions($task, $transactions); // reload the task now that we've done all the fun stuff return id(new ManiphestTaskQuery())->setViewer($request->getUser())->withPHIDs(array($task->getPHID()))->needSubscriberPHIDs(true)->needProjectPHIDs(true)->executeOne(); }
protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $change_data = $request->getValue('changes'); $changes = array(); foreach ($change_data as $dict) { $changes[] = ArcanistDiffChange::newFromDictionary($dict); } $diff = DifferentialDiff::newFromRawChanges($viewer, $changes); // TODO: Remove repository UUID eventually; for now continue writing // the UUID. Note that we'll overwrite it below if we identify a // repository, and `arc` no longer sends it. This stuff is retained for // backward compatibility. $repository_uuid = $request->getValue('repositoryUUID'); $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne(); if ($repository) { $repository_phid = $repository->getPHID(); $repository_uuid = $repository->getUUID(); } } switch ($request->getValue('lintStatus')) { case 'skip': $lint_status = DifferentialLintStatus::LINT_SKIP; break; case 'okay': $lint_status = DifferentialLintStatus::LINT_OKAY; break; case 'warn': $lint_status = DifferentialLintStatus::LINT_WARN; break; case 'fail': $lint_status = DifferentialLintStatus::LINT_FAIL; break; case 'none': default: $lint_status = DifferentialLintStatus::LINT_NONE; break; } switch ($request->getValue('unitStatus')) { case 'skip': $unit_status = DifferentialUnitStatus::UNIT_SKIP; break; case 'okay': $unit_status = DifferentialUnitStatus::UNIT_OKAY; break; case 'warn': $unit_status = DifferentialUnitStatus::UNIT_WARN; break; case 'fail': $unit_status = DifferentialUnitStatus::UNIT_FAIL; break; case 'none': default: $unit_status = DifferentialUnitStatus::UNIT_NONE; break; } $diff_data_dict = array('sourcePath' => $request->getValue('sourcePath'), 'sourceMachine' => $request->getValue('sourceMachine'), 'branch' => $request->getValue('branch'), 'creationMethod' => $request->getValue('creationMethod'), 'authorPHID' => $viewer->getPHID(), 'bookmark' => $request->getValue('bookmark'), 'repositoryUUID' => $repository_uuid, 'repositoryPHID' => $repository_phid, 'sourceControlSystem' => $request->getValue('sourceControlSystem'), 'sourceControlPath' => $request->getValue('sourceControlPath'), 'sourceControlBaseRevision' => $request->getValue('sourceControlBaseRevision'), 'lintStatus' => $lint_status, 'unitStatus' => $unit_status); $xactions = array(id(new DifferentialDiffTransaction())->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)->setNewValue($diff_data_dict)); id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->applyTransactions($diff, $xactions); $path = '/differential/diff/' . $diff->getID() . '/'; $uri = PhabricatorEnv::getURI($path); return array('diffid' => $diff->getID(), 'phid' => $diff->getPHID(), 'uri' => $uri); }
protected function applyFieldEdit(ConduitAPIRequest $request, DifferentialRevision $revision, DifferentialDiff $diff, array $fields, $message) { $viewer = $request->getUser(); $field_list = PhabricatorCustomField::getObjectFields($revision, DifferentialCustomField::ROLE_COMMITMESSAGEEDIT); $field_list->setViewer($viewer)->readFieldsFromStorage($revision); $field_map = mpull($field_list->getFields(), null, 'getFieldKeyForConduit'); $xactions = array(); $xactions[] = id(new DifferentialTransaction())->setTransactionType(DifferentialTransaction::TYPE_UPDATE)->setNewValue($diff->getPHID()); $values = $request->getValue('fields', array()); foreach ($values as $key => $value) { $field = idx($field_map, $key); if (!$field) { // NOTE: We're just ignoring fields we don't know about. This isn't // ideal, but the way the workflow currently works involves us getting // several read-only fields, like the revision ID field, which we should // just skip. continue; } $role = PhabricatorCustomField::ROLE_APPLICATIONTRANSACTIONS; if (!$field->shouldEnableForRole($role)) { continue; } // TODO: This is fairly similar to PhabricatorCustomField's // buildFieldTransactionsFromRequest() method, but that's currently not // easy to reuse. $transaction_type = $field->getApplicationTransactionType(); $xaction = id(new DifferentialTransaction())->setTransactionType($transaction_type); if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) { // For TYPE_CUSTOMFIELD transactions only, we provide the old value // as an input. $old_value = $field->getOldValueForApplicationTransactions(); $xaction->setOldValue($old_value); } // The transaction itself will be validated so this is somewhat // redundant, but this validator will sometimes give us a better error // message or a better reaction to a bad value type. $field->validateCommitMessageValue($value); $field->readValueFromCommitMessage($value); $xaction->setNewValue($field->getNewValueForApplicationTransactions()); if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) { // For TYPE_CUSTOMFIELD transactions, add the field key in metadata. $xaction->setMetadataValue('customfield:key', $field->getFieldKey()); } $metadata = $field->getApplicationTransactionMetadata(); foreach ($metadata as $meta_key => $meta_value) { $xaction->setMetadataValue($meta_key, $meta_value); } $xactions[] = $xaction; } $message = $request->getValue('message'); if (strlen($message)) { // This is a little awkward, and should maybe move inside the transaction // editor. It largely exists for legacy reasons. $first_line = head(phutil_split_lines($message, false)); $diff->setDescription($first_line); $diff->save(); $xactions[] = id(new DifferentialTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new DifferentialTransactionComment())->setContent($message)); } $editor = id(new DifferentialTransactionEditor())->setActor($viewer)->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true); $editor->applyTransactions($revision, $xactions); }