Path: blob/master/src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php
12256 views
<?php12final class DifferentialCreateRawDiffConduitAPIMethod3extends DifferentialConduitAPIMethod {45public function getAPIMethodName() {6return 'differential.createrawdiff';7}89public function getMethodDescription() {10return pht('Create a new Differential diff from a raw diff source.');11}1213protected function defineParamTypes() {14return array(15'diff' => 'required string',16'repositoryPHID' => 'optional string',17'viewPolicy' => 'optional string',18);19}2021protected function defineReturnType() {22return 'nonempty dict';23}2425protected function execute(ConduitAPIRequest $request) {26$viewer = $request->getUser();27$raw_diff = $request->getValue('diff');28if ($raw_diff === null || !strlen($raw_diff)) {29throw new Exception(pht('Field "raw_diff" must be non-empty.'));30}3132$repository_phid = $request->getValue('repositoryPHID');33if ($repository_phid) {34$repository = id(new PhabricatorRepositoryQuery())35->setViewer($viewer)36->withPHIDs(array($repository_phid))37->executeOne();38if (!$repository) {39throw new Exception(40pht('No such repository "%s"!', $repository_phid));41}42}4344$parser = new ArcanistDiffParser();45$changes = $parser->parseDiff($raw_diff);46$diff = DifferentialDiff::newFromRawChanges($viewer, $changes);4748// We're bounded by doing INSERTs for all the hunks and changesets, so49// estimate the number of inserts we'll require.50$size = 0;51foreach ($diff->getChangesets() as $changeset) {52$hunks = $changeset->getHunks();53$size += 1 + count($hunks);54}5556$raw_limit = 10000;57if ($size > $raw_limit) {58throw new Exception(59pht(60'The raw diff you have submitted is too large to parse (it affects '.61'more than %s paths and hunks).',62new PhutilNumber($raw_limit)));63}6465$diff_data_dict = array(66'creationMethod' => 'web',67'authorPHID' => $viewer->getPHID(),68'repositoryPHID' => $repository_phid,69'lintStatus' => DifferentialLintStatus::LINT_SKIP,70'unitStatus' => DifferentialUnitStatus::UNIT_SKIP,71);7273$xactions = array(74id(new DifferentialDiffTransaction())75->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)76->setNewValue($diff_data_dict),77);7879if ($request->getValue('viewPolicy')) {80$xactions[] = id(new DifferentialDiffTransaction())81->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)82->setNewValue($request->getValue('viewPolicy'));83}8485id(new DifferentialDiffEditor())86->setActor($viewer)87->setContentSource($request->newContentSource())88->setContinueOnNoEffect(true)89->setLookupRepository(false) // respect user choice90->applyTransactions($diff, $xactions);9192return $this->buildDiffInfoDictionary($diff);93}9495}969798