From 01844087cd85af77a00b7f4e1b6adef1717c40fe Mon Sep 17 00:00:00 2001 From: tuomaspelkonen Date: Tue, 19 Apr 2011 16:24:45 -0700 Subject: [PATCH] Added a conduit method for querying revision feedback. Summary: Push tools needs information about differential revision comments. Added a method that returns the needed information. Test Plan: Tested that /intern/push/merges shows correct information. Reviewed By: jungejason Reviewers: jungejason CC: epriestley, jungejason Differential Revision: 152 --- src/__phutil_library_map__.php | 2 + ...ifferential_getrevisionfeedback_Method.php | 72 +++++++++++++++++++ .../getrevisionfeedback/__init__.php | 15 ++++ 3 files changed, 89 insertions(+) create mode 100644 src/applications/conduit/method/differential/getrevisionfeedback/ConduitAPI_differential_getrevisionfeedback_Method.php create mode 100644 src/applications/conduit/method/differential/getrevisionfeedback/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e5685d3268..8e3bd588ce 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -81,6 +81,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_getcommitmessage_Method' => 'applications/conduit/method/differential/getcommitmessage', 'ConduitAPI_differential_getcommitpaths_Method' => 'applications/conduit/method/differential/getcommitpaths', 'ConduitAPI_differential_getdiff_Method' => 'applications/conduit/method/differential/getdiff', + 'ConduitAPI_differential_getrevisionfeedback_Method' => 'applications/conduit/method/differential/getrevisionfeedback', 'ConduitAPI_differential_markcommitted_Method' => 'applications/conduit/method/differential/markcommitted', 'ConduitAPI_differential_parsecommitmessage_Method' => 'applications/conduit/method/differential/parsecommitmessage', 'ConduitAPI_differential_setdiffproperty_Method' => 'applications/conduit/method/differential/setdiffproperty', @@ -527,6 +528,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_getcommitmessage_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_getcommitpaths_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_getdiff_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_getrevisionfeedback_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_markcommitted_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/differential/getrevisionfeedback/ConduitAPI_differential_getrevisionfeedback_Method.php b/src/applications/conduit/method/differential/getrevisionfeedback/ConduitAPI_differential_getrevisionfeedback_Method.php new file mode 100644 index 0000000000..fcd351d309 --- /dev/null +++ b/src/applications/conduit/method/differential/getrevisionfeedback/ConduitAPI_differential_getrevisionfeedback_Method.php @@ -0,0 +1,72 @@ + 'required list', + ); + } + + public function defineReturnType() { + return 'nonempty list>'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $results = array(); + $revision_ids = $request->getValue('ids'); + + if (!$revision_ids) { + return $results; + } + + $comments = id(new DifferentialComment())->loadAllWhere( + 'revisionID IN (%Ld)', + $revision_ids); + + // Helper dictionary to keep track of where the id/action pair is + // stored in results array. + $indexes = array(); + foreach ($comments as $comment) { + $action = $comment->getAction(); + $revision_id = $comment->getRevisionID(); + + if (isset($indexes[$action.$revision_id])) { + $results[$indexes[$action.$revision_id]]['count']++; + } else { + $indexes[$action.$revision_id] = count($results); + $results[] = array('id' => $revision_id, + 'action' => $action, + 'count' => 1); + } + } + + return $results; + } +} diff --git a/src/applications/conduit/method/differential/getrevisionfeedback/__init__.php b/src/applications/conduit/method/differential/getrevisionfeedback/__init__.php new file mode 100644 index 0000000000..2987d4776f --- /dev/null +++ b/src/applications/conduit/method/differential/getrevisionfeedback/__init__.php @@ -0,0 +1,15 @@ +