protected function execute(ConduitAPIRequest $request) { $source_phid = $request->getValue('sourcePHID'); $owner_phid = $request->getValue('ownerPHID'); $requestor_phid = $request->getValue('requestorPHID'); $user = $request->getUser(); $item = NuanceItem::initializeNewItem(); $xactions = array(); if ($source_phid) { $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_SOURCE)->setNewValue($source_phid); } else { throw new ConduitException('ERR-NO-SOURCE-PHID'); } if ($owner_phid) { $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_OWNER)->setNewValue($owner_phid); } if ($requestor_phid) { $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_REQUESTOR)->setNewValue($requestor_phid); } else { throw new ConduitException('ERR-NO-REQUESTOR-PHID'); } $source = PhabricatorContentSource::newFromConduitRequest($request); $editor = id(new NuanceItemEditor())->setActor($user)->setContentSource($source)->applyTransactions($item, $xactions); return $item->toDictionary(); }
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)); } } else { $repository = null; } $parser = new ArcanistDiffParser(); $changes = $parser->parseDiff($raw_diff); $diff = DifferentialDiff::newFromRawChanges($changes); $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); $diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP); $diff->setAuthorPHID($viewer->getPHID()); $diff->setCreationMethod('web'); if ($repository) { $diff->setRepositoryPHID($repository->getPHID()); } id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromConduitRequest($request))->saveDiff($diff); return $this->buildDiffInfoDictionary($diff); }
protected function execute(ConduitAPIRequest $request) { $content_source = PhabricatorContentSource::newFromConduitRequest($request); $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) { $user = $request->getUser(); $id = $request->getValue('id'); $phid = $request->getValue('phid'); $query = id(new ConpherenceThreadQuery())->setViewer($user)->needFilePHIDs(true); if ($id) { $query->withIDs(array($id)); } else { if ($phid) { $query->withPHIDs(array($phid)); } else { throw new ConduitException('ERR_USAGE_NO_THREAD_ID'); } } $conpherence = $query->executeOne(); if (!$conpherence) { throw new ConduitException('ERR_USAGE_THREAD_NOT_FOUND'); } $source = PhabricatorContentSource::newFromConduitRequest($request); $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) { $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, PhabricatorContentSource::newFromConduitRequest($request)); 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) { $viewer = $request->getUser(); $change_data = $request->getValue('changes'); $changes = array(); foreach ($change_data as $dict) { $changes[] = ArcanistDiffChange::newFromDictionary($dict); } $diff = DifferentialDiff::newFromRawChanges($changes); $diff->setSourcePath($request->getValue('sourcePath')); $diff->setSourceMachine($request->getValue('sourceMachine')); $diff->setBranch($request->getValue('branch')); $diff->setCreationMethod($request->getValue('creationMethod')); $diff->setAuthorPHID($viewer->getPHID()); $diff->setBookmark($request->getValue('bookmark')); // TODO: Remove this 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. $diff->setRepositoryUUID($request->getValue('repositoryUUID')); $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne(); if ($repository) { $diff->setRepositoryPHID($repository->getPHID()); $diff->setRepositoryUUID($repository->getUUID()); } } $system = $request->getValue('sourceControlSystem'); $diff->setSourceControlSystem($system); $diff->setSourceControlPath($request->getValue('sourceControlPath')); $diff->setSourceControlBaseRevision($request->getValue('sourceControlBaseRevision')); $project_name = $request->getValue('arcanistProject'); $project_phid = null; if ($project_name) { $arcanist_project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere('name = %s', $project_name); if (!$arcanist_project) { $arcanist_project = new PhabricatorRepositoryArcanistProject(); $arcanist_project->setName($project_name); $arcanist_project->save(); } $project_phid = $arcanist_project->getPHID(); } $diff->setArcanistProjectPHID($project_phid); switch ($request->getValue('lintStatus')) { case 'skip': $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); break; case 'okay': $diff->setLintStatus(DifferentialLintStatus::LINT_OKAY); break; case 'warn': $diff->setLintStatus(DifferentialLintStatus::LINT_WARN); break; case 'fail': $diff->setLintStatus(DifferentialLintStatus::LINT_FAIL); break; case 'postponed': $diff->setLintStatus(DifferentialLintStatus::LINT_POSTPONED); break; case 'none': default: $diff->setLintStatus(DifferentialLintStatus::LINT_NONE); break; } switch ($request->getValue('unitStatus')) { case 'skip': $diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP); break; case 'okay': $diff->setUnitStatus(DifferentialUnitStatus::UNIT_OKAY); break; case 'warn': $diff->setUnitStatus(DifferentialUnitStatus::UNIT_WARN); break; case 'fail': $diff->setUnitStatus(DifferentialUnitStatus::UNIT_FAIL); break; case 'postponed': $diff->setUnitStatus(DifferentialUnitStatus::UNIT_POSTPONED); break; case 'none': default: $diff->setUnitStatus(DifferentialUnitStatus::UNIT_NONE); break; } id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromConduitRequest($request))->saveDiff($diff); // If we didn't get an explicit `repositoryPHID` (which means the client is // old, or couldn't figure out which repository the working copy belongs // to), apply heuristics to try to figure it out. if (!$repository_phid) { $repository = id(new DifferentialRepositoryLookup())->setDiff($diff)->setViewer($viewer)->lookupRepository(); if ($repository) { $diff->setRepositoryPHID($repository->getPHID()); $diff->setRepositoryUUID($repository->getUUID()); $diff->save(); } } $path = '/differential/diff/' . $diff->getID() . '/'; $uri = PhabricatorEnv::getURI($path); return array('diffid' => $diff->getID(), 'uri' => $uri); }