From 16895e109979067dcfe198af7ae77330b3f9e1b6 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Mon, 9 Sep 2013 14:25:08 -0700 Subject: [PATCH] Add "diffusion.createcomment" conduit endpoint Summary: Adds most of Diffusion's commenting options available in the web UI Mark method as deprecated immediately per @epriestley's request Test Plan: Used the Conduit web console to check: * Lookup by PHID works * Error is raised if commit by PHID is not found * "action" validation works and raises appropriate error * "message" raises error if empty * Actions to raise concern or accept commit work * Method is marked as deprecated from the start Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Differential Revision: https://secure.phabricator.com/D6923 --- src/__phutil_library_map__.php | 2 + ...duitAPI_diffusion_createcomment_Method.php | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/applications/diffusion/conduit/ConduitAPI_diffusion_createcomment_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 330c1f9514..65eb7e9464 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -147,6 +147,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_browsequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_browsequery_Method.php', 'ConduitAPI_diffusion_commitbranchesquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_commitbranchesquery_Method.php', 'ConduitAPI_diffusion_commitparentsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_commitparentsquery_Method.php', + 'ConduitAPI_diffusion_createcomment_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_createcomment_Method.php', 'ConduitAPI_diffusion_diffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_diffquery_Method.php', 'ConduitAPI_diffusion_existsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_existsquery_Method.php', 'ConduitAPI_diffusion_expandshortcommitquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_expandshortcommitquery_Method.php', @@ -2197,6 +2198,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_browsequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_commitbranchesquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_commitparentsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', + 'ConduitAPI_diffusion_createcomment_Method' => 'ConduitAPI_diffusion_Method', 'ConduitAPI_diffusion_diffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_existsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 'ConduitAPI_diffusion_expandshortcommitquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', diff --git a/src/applications/diffusion/conduit/ConduitAPI_diffusion_createcomment_Method.php b/src/applications/diffusion/conduit/ConduitAPI_diffusion_createcomment_Method.php new file mode 100644 index 0000000000..692246497f --- /dev/null +++ b/src/applications/diffusion/conduit/ConduitAPI_diffusion_createcomment_Method.php @@ -0,0 +1,83 @@ + 'required string', + 'action' => 'optional string', + 'message' => 'required string', + ); + } + + public function defineReturnType() { + return 'bool'; + } + + public function defineErrorTypes() { + return array( + 'ERR_BAD_COMMIT' => 'No commit found with that PHID', + 'ERR_BAD_ACTION' => 'Invalid action type', + 'ERR_MISSING_MESSAGE' => 'Message is required', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $commit_phid = $request->getValue('phid'); + $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( + 'phid = %s', + $commit_phid); + + 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 for now + if (!in_array($action, array( + PhabricatorAuditActionConstants::CONCERN, + PhabricatorAuditActionConstants::ACCEPT, + PhabricatorAuditActionConstants::COMMENT, + PhabricatorAuditActionConstants::RESIGN, + PhabricatorAuditActionConstants::CLOSE, + ))) { + throw new ConduitException('ERR_BAD_ACTION'); + } + + $comment = id(new PhabricatorAuditComment()) + ->setAction($action) + ->setContent($message); + + id(new PhabricatorAuditCommentEditor($commit)) + ->setActor($request->getUser()) + ->addComment($comment); + + return true; + // get the full uri of the comment? + // i.e, PhabricatorEnv::getURI(rXX01ab23cd#comment-9) + } + +}