@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.

Policy - clean up the deprecated diffusion.getcommits

Summary: Ref T7094. Could just delete this end point too I guess? Needed to add "withCommitPHIDs" to the differentialrevisionquery to get this done.

Test Plan: used diffusion.getcommits from conduit console and got a sensible result for a query for two commits, one with a diff and one without.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7094

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

+51 -24
+29
src/applications/differential/query/DifferentialRevisionQuery.php
··· 32 32 private $reviewers = array(); 33 33 private $revIDs = array(); 34 34 private $commitHashes = array(); 35 + private $commitPHIDs = array(); 35 36 private $phids = array(); 36 37 private $responsibles = array(); 37 38 private $branches = array(); ··· 150 151 */ 151 152 public function withCommitHashes(array $commit_hashes) { 152 153 $this->commitHashes = $commit_hashes; 154 + return $this; 155 + } 156 + 157 + /** 158 + * Filter results to revisions that have one of the provided PHIDs as 159 + * commits. Calling this function will clear anything set by previous calls 160 + * to @{method:withCommitPHIDs}. 161 + * 162 + * @param array List of PHIDs of commits 163 + * @return this 164 + * @task config 165 + */ 166 + public function withCommitPHIDs(array $commit_phids) { 167 + $this->commitPHIDs = $commit_phids; 153 168 return $this; 154 169 } 155 170 ··· 653 668 $this->draftAuthors); 654 669 } 655 670 671 + if ($this->commitPHIDs) { 672 + $joins[] = qsprintf( 673 + $conn_r, 674 + 'JOIN %T commits ON commits.revisionID = r.id', 675 + DifferentialRevision::TABLE_COMMIT); 676 + } 677 + 656 678 $joins = implode(' ', $joins); 657 679 658 680 return $joins; ··· 712 734 } 713 735 $hash_clauses = '('.implode(' OR ', $hash_clauses).')'; 714 736 $where[] = $hash_clauses; 737 + } 738 + 739 + if ($this->commitPHIDs) { 740 + $where[] = qsprintf( 741 + $conn_r, 742 + 'commits.commitPHID IN (%Ls)', 743 + $this->commitPHIDs); 715 744 } 716 745 717 746 if ($this->phids) {
+22 -24
src/applications/diffusion/conduit/DiffusionGetCommitsConduitAPIMethod.php
··· 135 135 } 136 136 137 137 $commits = $this->addRepositoryCommitDataInformation($commits); 138 - $commits = $this->addDifferentialInformation($commits); 138 + $commits = $this->addDifferentialInformation($commits, $request); 139 139 $commits = $this->addManiphestInformation($commits); 140 140 141 141 foreach ($commits as $name => $commit) { ··· 238 238 /** 239 239 * Enhance the commit list with Differential information. 240 240 */ 241 - private function addDifferentialInformation(array $commits) { 242 - $commit_phids = ipull($commits, 'commitPHID'); 241 + private function addDifferentialInformation( 242 + array $commits, 243 + ConduitAPIRequest $request) { 243 244 244 - // TODO: (T603) This should be policy checked, either by moving to 245 - // DifferentialRevisionQuery or by doing a followup query to make sure 246 - // the matched objects are visible. 247 - 248 - $rev_conn_r = id(new DifferentialRevision())->establishConnection('r'); 249 - $revs = queryfx_all( 250 - $rev_conn_r, 251 - 'SELECT r.id id, r.phid phid, c.commitPHID commitPHID FROM %T r JOIN %T c 252 - ON r.id = c.revisionID 253 - WHERE c.commitPHID in (%Ls)', 254 - id(new DifferentialRevision())->getTableName(), 255 - DifferentialRevision::TABLE_COMMIT, 256 - $commit_phids); 245 + $commit_phids = ipull($commits, 'commitPHID'); 257 246 258 - $revs = ipull($revs, null, 'commitPHID'); 259 - foreach ($commits as $name => $commit) { 260 - if (isset($revs[$commit['commitPHID']])) { 261 - $rev = $revs[$commit['commitPHID']]; 262 - $commits[$name] += array( 263 - 'differentialRevisionID' => 'D'.$rev['id'], 264 - 'differentialRevisionPHID' => $rev['phid'], 265 - ); 247 + $revisions = id(new DifferentialRevisionQuery()) 248 + ->setViewer($request->getUser()) 249 + ->withCommitPHIDs($commit_phids) 250 + ->needCommitPHIDs(true) 251 + ->execute(); 252 + $rev_phid_commit_phids_map = mpull($revisions, 'getCommitPHIDs', 'getPHID'); 253 + $revisions = mpull($revisions, null, 'getPHID'); 254 + foreach ($rev_phid_commit_phids_map as $rev_phid => $commit_phids) { 255 + foreach ($commits as $name => $commit) { 256 + $commit_phid = $commit['commitPHID']; 257 + if (in_array($commit_phid, $commit_phids)) { 258 + $revision = $revisions[$rev_phid]; 259 + $commits[$name] += array( 260 + 'differentialRevisionID' => 'D'.$revision->getID(), 261 + 'differentialRevisionPHID' => $revision->getPHID(), 262 + ); 263 + } 266 264 } 267 265 } 268 266