From fa5bcf5d9478b41cb4bdaa23f22eef1aab4dfc6c Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 24 Aug 2017 15:15:16 -0700 Subject: [PATCH] Provide some more detailed information about inline comments in "transaction.search" Summary: Ref T5873. This provides paths and line numbers for inline comments. This is a touch hacky but I was able to keep it mostly under control. Test Plan: - Made inline comments. - Called API, got path/line information. {F5120157} Reviewers: chad Reviewed By: chad Maniphest Tasks: T5873 Differential Revision: https://secure.phabricator.com/D18469 --- src/__phutil_library_map__.php | 2 + .../DifferentialRevisionInlineTransaction.php | 53 +++++++++++++++++++ .../TransactionSearchConduitAPIMethod.php | 23 +++++++- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/applications/differential/xaction/DifferentialRevisionInlineTransaction.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f732fdb33b..f0c9271634 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -544,6 +544,7 @@ phutil_register_library_map(array( 'DifferentialRevisionHeraldField' => 'applications/differential/herald/DifferentialRevisionHeraldField.php', 'DifferentialRevisionHeraldFieldGroup' => 'applications/differential/herald/DifferentialRevisionHeraldFieldGroup.php', 'DifferentialRevisionIDCommitMessageField' => 'applications/differential/field/DifferentialRevisionIDCommitMessageField.php', + 'DifferentialRevisionInlineTransaction' => 'applications/differential/xaction/DifferentialRevisionInlineTransaction.php', 'DifferentialRevisionInlinesController' => 'applications/differential/controller/DifferentialRevisionInlinesController.php', 'DifferentialRevisionListController' => 'applications/differential/controller/DifferentialRevisionListController.php', 'DifferentialRevisionListView' => 'applications/differential/view/DifferentialRevisionListView.php', @@ -5547,6 +5548,7 @@ phutil_register_library_map(array( 'DifferentialRevisionHeraldField' => 'HeraldField', 'DifferentialRevisionHeraldFieldGroup' => 'HeraldFieldGroup', 'DifferentialRevisionIDCommitMessageField' => 'DifferentialCommitMessageField', + 'DifferentialRevisionInlineTransaction' => 'PhabricatorModularTransactionType', 'DifferentialRevisionInlinesController' => 'DifferentialController', 'DifferentialRevisionListController' => 'DifferentialController', 'DifferentialRevisionListView' => 'AphrontView', diff --git a/src/applications/differential/xaction/DifferentialRevisionInlineTransaction.php b/src/applications/differential/xaction/DifferentialRevisionInlineTransaction.php new file mode 100644 index 0000000000..9e566047ec --- /dev/null +++ b/src/applications/differential/xaction/DifferentialRevisionInlineTransaction.php @@ -0,0 +1,53 @@ +getViewer(); + + $changeset_ids = array(); + foreach ($xactions as $xaction) { + $changeset_ids[] = $xaction->getComment()->getChangesetID(); + } + + $changesets = id(new DifferentialChangesetQuery()) + ->setViewer($viewer) + ->withIDs($changeset_ids) + ->execute(); + + $changesets = mpull($changesets, null, 'getID'); + + return $changesets; + } + + public function getFieldValuesForConduit($object, $data) { + $comment = $object->getComment(); + + $changeset = $data[$comment->getChangesetID()]; + $diff = $changeset->getDiff(); + + return array( + 'diff' => array( + 'id' => $diff->getID(), + 'phid' => $diff->getPHID(), + ), + 'path' => $changeset->getDisplayFilename(), + 'line' => (int)$comment->getLineNumber(), + 'length' => (int)($comment->getLineLength() + 1), + 'replyToCommentPHID' => $comment->getReplyToCommentPHID(), + ); + } + +} diff --git a/src/applications/transactions/conduit/TransactionSearchConduitAPIMethod.php b/src/applications/transactions/conduit/TransactionSearchConduitAPIMethod.php index b3065b0d9c..43b94874bf 100644 --- a/src/applications/transactions/conduit/TransactionSearchConduitAPIMethod.php +++ b/src/applications/transactions/conduit/TransactionSearchConduitAPIMethod.php @@ -97,7 +97,18 @@ final class TransactionSearchConduitAPIMethod continue; } - $modular_template = $xaction->getModularType(); + // TODO: Hack things so certain transactions which don't have a modular + // type yet can use a pseudotype until they modularize. Some day, we'll + // modularize everything and remove this. + switch ($xaction->getTransactionType()) { + case DifferentialTransaction::TYPE_INLINE: + $modular_template = new DifferentialRevisionInlineTransaction(); + break; + default: + $modular_template = $xaction->getModularType(); + break; + } + $modular_class = get_class($modular_template); if (!isset($modular_objects[$modular_class])) { try { @@ -173,6 +184,16 @@ final class TransactionSearchConduitAPIMethod $fields = (object)$fields; } + // If we haven't found a modular type, fallback for some simple core + // types. Ideally, we'll modularize everything some day. + if ($type === null) { + switch ($xaction->getTransactionType()) { + case PhabricatorTransactions::TYPE_COMMENT: + $type = 'comment'; + break; + } + } + $data[] = array( 'id' => (int)$xaction->getID(), 'phid' => (string)$xaction->getPHID(),