@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Provide a "differential.changeset.search" Conduit API method

Summary: Ref T13605. Support selecting a diff's changesets (to get a list of affected file paths) via the API.

Test Plan: Called API with no arguments, diffPHIDs, PHIDs, IDs. Got sensible output.

Maniphest Tasks: T13605

Differential Revision: https://secure.phabricator.com/D21558

+118 -2
+3
src/__phutil_library_map__.php
··· 477 477 'DifferentialChangesetParserTestCase' => 'applications/differential/parser/__tests__/DifferentialChangesetParserTestCase.php', 478 478 'DifferentialChangesetQuery' => 'applications/differential/query/DifferentialChangesetQuery.php', 479 479 'DifferentialChangesetRenderer' => 'applications/differential/render/DifferentialChangesetRenderer.php', 480 + 'DifferentialChangesetSearchConduitAPIMethod' => 'applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php', 480 481 'DifferentialChangesetSearchEngine' => 'applications/differential/query/DifferentialChangesetSearchEngine.php', 481 482 'DifferentialChangesetTestRenderer' => 'applications/differential/render/DifferentialChangesetTestRenderer.php', 482 483 'DifferentialChangesetTwoUpRenderer' => 'applications/differential/render/DifferentialChangesetTwoUpRenderer.php', ··· 6533 6534 'DifferentialDAO', 6534 6535 'PhabricatorPolicyInterface', 6535 6536 'PhabricatorDestructibleInterface', 6537 + 'PhabricatorConduitResultInterface', 6536 6538 ), 6537 6539 'DifferentialChangesetDetailView' => 'AphrontView', 6538 6540 'DifferentialChangesetEngine' => 'Phobject', ··· 6547 6549 'DifferentialChangesetParserTestCase' => 'PhabricatorTestCase', 6548 6550 'DifferentialChangesetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6549 6551 'DifferentialChangesetRenderer' => 'Phobject', 6552 + 'DifferentialChangesetSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 6550 6553 'DifferentialChangesetSearchEngine' => 'PhabricatorApplicationSearchEngine', 6551 6554 'DifferentialChangesetTestRenderer' => 'DifferentialChangesetRenderer', 6552 6555 'DifferentialChangesetTwoUpRenderer' => 'DifferentialChangesetHTMLRenderer',
+18
src/applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class DifferentialChangesetSearchConduitAPIMethod 4 + extends PhabricatorSearchEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'differential.changeset.search'; 8 + } 9 + 10 + public function newSearchEngine() { 11 + return new DifferentialChangesetSearchEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht('Read information about changesets.'); 16 + } 17 + 18 + }
+38
src/applications/differential/query/DifferentialChangesetQuery.php
··· 4 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 5 6 6 private $ids; 7 + private $phids; 8 + private $diffPHIDs; 9 + 7 10 private $diffs; 8 11 9 12 private $needAttachToDiffs; ··· 14 17 return $this; 15 18 } 16 19 20 + public function withPHIDs(array $phids) { 21 + $this->phids = $phids; 22 + return $this; 23 + } 24 + 17 25 public function withDiffs(array $diffs) { 18 26 assert_instances_of($diffs, 'DifferentialDiff'); 19 27 $this->diffs = $diffs; 28 + return $this; 29 + } 30 + 31 + public function withDiffPHIDs(array $phids) { 32 + $this->diffPHIDs = $phids; 20 33 return $this; 21 34 } 22 35 ··· 132 145 $conn, 133 146 'id IN (%Ld)', 134 147 $this->ids); 148 + } 149 + 150 + if ($this->phids !== null) { 151 + $where[] = qsprintf( 152 + $conn, 153 + 'phid IN (%Ls)', 154 + $this->phids); 155 + } 156 + 157 + if ($this->diffPHIDs !== null) { 158 + $diff_ids = queryfx_all( 159 + $conn, 160 + 'SELECT id FROM %R WHERE phid IN (%Ls)', 161 + new DifferentialDiff(), 162 + $this->diffPHIDs); 163 + $diff_ids = ipull($diff_ids, 'id', null); 164 + 165 + if (!$diff_ids) { 166 + throw new PhabricatorEmptyQueryException(); 167 + } 168 + 169 + $where[] = qsprintf( 170 + $conn, 171 + 'diffID IN (%Ld)', 172 + $diff_ids); 135 173 } 136 174 137 175 return $where;
+13 -1
src/applications/differential/query/DifferentialChangesetSearchEngine.php
··· 38 38 39 39 protected function buildQueryFromParameters(array $map) { 40 40 $query = $this->newQuery(); 41 + 42 + if ($map['diffPHIDs']) { 43 + $query->withDiffPHIDs($map['diffPHIDs']); 44 + } 45 + 41 46 return $query; 42 47 } 43 48 44 49 protected function buildCustomSearchFields() { 45 - return array(); 50 + return array( 51 + id(new PhabricatorPHIDsSearchField()) 52 + ->setLabel(pht('Diffs')) 53 + ->setKey('diffPHIDs') 54 + ->setAliases(array('diff', 'diffs', 'diffPHID')) 55 + ->setDescription( 56 + pht('Find changesets attached to a particular diff.')), 57 + ); 46 58 } 47 59 48 60 protected function getURI($path) {
+46 -1
src/applications/differential/storage/DifferentialChangeset.php
··· 4 4 extends DifferentialDAO 5 5 implements 6 6 PhabricatorPolicyInterface, 7 - PhabricatorDestructibleInterface { 7 + PhabricatorDestructibleInterface, 8 + PhabricatorConduitResultInterface { 8 9 9 10 protected $diffID; 10 11 protected $oldFile; ··· 733 734 $this->delete(); 734 735 735 736 $this->saveTransaction(); 737 + } 738 + 739 + /* -( PhabricatorConduitResultInterface )---------------------------------- */ 740 + 741 + public function getFieldSpecificationsForConduit() { 742 + return array( 743 + id(new PhabricatorConduitSearchFieldSpecification()) 744 + ->setKey('diffPHID') 745 + ->setType('phid') 746 + ->setDescription(pht('The diff the changeset is attached to.')), 747 + ); 748 + } 749 + 750 + public function getFieldValuesForConduit() { 751 + $diff = $this->getDiff(); 752 + 753 + $repository = null; 754 + if ($diff) { 755 + $revision = $diff->getRevision(); 756 + if ($revision) { 757 + $repository = $revision->getRepository(); 758 + } 759 + } 760 + 761 + $absolute_path = $this->getAbsoluteRepositoryPath($repository, $diff); 762 + if (strlen($absolute_path)) { 763 + $absolute_path = base64_encode($absolute_path); 764 + } else { 765 + $absolute_path = null; 766 + } 767 + 768 + $display_path = $this->getDisplayFilename(); 769 + 770 + return array( 771 + 'diffPHID' => $diff->getPHID(), 772 + 'path' => array( 773 + 'displayPath' => $display_path, 774 + 'absolutePath.base64' => $absolute_path, 775 + ), 776 + ); 777 + } 778 + 779 + public function getConduitSearchAttachments() { 780 + return array(); 736 781 } 737 782 738 783