From 8065d728996644e82fb9fed5cb909e0546d5c1d4 Mon Sep 17 00:00:00 2001 From: Alan Huang Date: Mon, 16 Jul 2012 11:49:06 -0700 Subject: [PATCH] Add a differential.createinline method to Conduit Summary: a silly thing because I was bored Test Plan: and I said "arc call-conduit", and there were comments Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1500 Differential Revision: https://secure.phabricator.com/D2971 --- src/__phutil_library_map__.php | 26 ++-- ...itAPI_differential_createinline_Method.php | 130 ++++++++++++++++++ 2 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 src/applications/conduit/method/differential/ConduitAPI_differential_createinline_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index dd3af5b8d9..e398a3c9c5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -135,6 +135,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_close_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_close_Method.php', 'ConduitAPI_differential_createcomment_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createcomment_Method.php', 'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_creatediff_Method.php', + 'ConduitAPI_differential_createinline_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createinline_Method.php', 'ConduitAPI_differential_createrawdiff_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createrawdiff_Method.php', 'ConduitAPI_differential_createrevision_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createrevision_Method.php', 'ConduitAPI_differential_find_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_find_Method.php', @@ -1228,6 +1229,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_close_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_createcomment_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_createinline_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_createrawdiff_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_createrevision_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_find_Method' => 'ConduitAPIMethod', @@ -1549,7 +1551,11 @@ phutil_register_library_map(array( 'ManiphestSavedQueryEditController' => 'ManiphestController', 'ManiphestSavedQueryListController' => 'ManiphestController', 'ManiphestSubpriorityController' => 'ManiphestController', - 'ManiphestTask' => 'ManiphestDAO', + 'ManiphestTask' => + array( + 0 => 'ManiphestDAO', + 1 => 'PhabricatorMarkupInterface', + ), 'ManiphestTaskAuxiliaryStorage' => 'ManiphestDAO', 'ManiphestTaskDescriptionChangeController' => 'ManiphestController', 'ManiphestTaskDescriptionPreviewController' => 'ManiphestController', @@ -1564,7 +1570,11 @@ phutil_register_library_map(array( 'ManiphestTaskStatus' => 'ManiphestConstants', 'ManiphestTaskSubscriber' => 'ManiphestDAO', 'ManiphestTaskSummaryView' => 'ManiphestView', - 'ManiphestTransaction' => 'ManiphestDAO', + 'ManiphestTransaction' => + array( + 0 => 'ManiphestDAO', + 1 => 'PhabricatorMarkupInterface', + ), 'ManiphestTransactionDetailView' => 'ManiphestView', 'ManiphestTransactionListView' => 'ManiphestView', 'ManiphestTransactionPreviewController' => 'ManiphestController', @@ -2039,16 +2049,16 @@ phutil_register_library_map(array( 'PhortuneStripeTestPaymentFormController' => 'PhortuneStripeBaseController', 'PhrictionActionConstants' => 'PhrictionConstants', 'PhrictionChangeType' => 'PhrictionConstants', - 'PhrictionContent' => 'PhrictionDAO', - 'PhrictionController' => 'PhabricatorController', - 'PhrictionDAO' => 'PhabricatorLiskDAO', - 'PhrictionDeleteController' => 'PhrictionController', - 'PhrictionDiffController' => 'PhrictionController', - 'PhrictionDocument' => + 'PhrictionContent' => array( 0 => 'PhrictionDAO', 1 => 'PhabricatorMarkupInterface', ), + 'PhrictionController' => 'PhabricatorController', + 'PhrictionDAO' => 'PhabricatorLiskDAO', + 'PhrictionDeleteController' => 'PhrictionController', + 'PhrictionDiffController' => 'PhrictionController', + 'PhrictionDocument' => 'PhrictionDAO', 'PhrictionDocumentController' => 'PhrictionController', 'PhrictionDocumentPreviewController' => 'PhrictionController', 'PhrictionDocumentStatus' => 'PhrictionConstants', diff --git a/src/applications/conduit/method/differential/ConduitAPI_differential_createinline_Method.php b/src/applications/conduit/method/differential/ConduitAPI_differential_createinline_Method.php new file mode 100644 index 0000000000..0ffa7fd30c --- /dev/null +++ b/src/applications/conduit/method/differential/ConduitAPI_differential_createinline_Method.php @@ -0,0 +1,130 @@ + 'optional revisionid', + 'diffID' => 'optional diffid', + 'filePath' => 'required string', + 'isNewFile' => 'required bool', + 'lineStart' => 'required int', + 'lineCount' => 'optional int', + 'message' => 'required string', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR-BAD-REVISION' => 'Bad revision ID.', + 'ERR-BAD-DIFF' => 'Bad diff ID, or diff does not belong to revision.', + 'ERR-NEED-DIFF' => 'Neither revision ID nor diff ID was provided.', + 'ERR-NEED-FILE' => 'A file path was not provided.', + 'ERR-BAD-FILE' => "Requested file doesn't exist in this revision." + ); + } + + protected function execute(ConduitAPIRequest $request) { + $rid = $request->getValue('revisionID'); + $did = $request->getValue('diffID'); + + if ($rid) { + // Given both a revision and a diff, check that they match. + // Given only a revision, find the active diff. + $revision = id(new DifferentialRevision())->load($rid); + if (!$revision) { + throw new ConduitException('ERR-BAD-REVISION'); + } + + if (!$did) { // did not! + $diff = $revision->loadActiveDiff(); + $did = $diff->getID(); + } else { // did too! + $diff = id(new DifferentialDiff())->load($did); + if (!$diff || $diff->getRevisionID() != $rid) { + throw new ConduitException('ERR-BAD-DIFF'); + } + } + } else if ($did) { + // Given only a diff, find the parent revision. + $diff = id(new DifferentialDiff())->load($did); + if (!$diff) { + throw new ConduitException('ERR-BAD-DIFF'); + } + $rid = $diff->getRevisionID(); + } else { + // Given neither, bail. + throw new ConduitException('ERR-NEED-DIFF'); + } + + $file = $request->getValue('filePath'); + if (!$file) { + throw new ConduitException('ERR-NEED-FILE'); + } + $changes = id(new DifferentialChangeset())->loadAllWhere( + 'diffID = %d', + $did); + $cid = null; + foreach ($changes as $id => $change) { + if ($file == $change->getFilename()) { + $cid = $id; + } + } + if ($cid == null) { + throw new ConduitException('ERR-BAD-FILE'); + } + + $inline = id(new DifferentialInlineComment()) + ->setRevisionID($rid) + ->setChangesetID($cid) + ->setAuthorPHID($request->getUser()->getPHID()) + ->setContent($request->getValue('message')) + ->setIsNewFile($request->getValue('isNewFile')) + ->setLineNumber($request->getValue('lineStart')) + ->setLineLength($request->getValue('lineCount', 0)) + ->save(); + + // Load everything again, just to be safe. + $changeset = id(new DifferentialChangeset()) + ->load($inline->getChangesetID()); + return array( + 'filePath' => ($inline->getIsNewFile() ? + $changeset->getFilename() : + $changeset->getOldFile()), + 'isNewFile' => $inline->getIsNewFile(), + 'lineNumber' => $inline->getLineNumber(), + 'lineLength' => $inline->getLineLength(), + 'diffID' => $changeset->getDiffID(), + 'content' => $inline->getContent(), + ); + } + +}