mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
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
This commit is contained in:
parent
9639ec0dfa
commit
fa5bcf5d94
3 changed files with 77 additions and 1 deletions
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialRevisionInlineTransaction
|
||||
extends PhabricatorModularTransactionType {
|
||||
|
||||
// NOTE: This class is NOT an actual Differential modular transaction type!
|
||||
// It does not extend "DifferentialRevisionTransactionType". Some day it
|
||||
// should, but for now it's just reducing the amount of hackiness around
|
||||
// supporting inline comments in the "transaction.search" Conduit API method.
|
||||
|
||||
const TRANSACTIONTYPE = 'internal.pretend-inline';
|
||||
|
||||
public function getTransactionTypeForConduit($xaction) {
|
||||
return 'inline';
|
||||
}
|
||||
|
||||
public function loadTransactionTypeConduitData(array $xactions) {
|
||||
$viewer = $this->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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue