@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
at upstream/main 122 lines 3.5 kB view raw
1<?php 2 3final class DiffusionQueryCommitsConduitAPIMethod 4 extends DiffusionConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'diffusion.querycommits'; 8 } 9 10 public function getMethodDescription() { 11 return pht('Retrieve information about commits.'); 12 } 13 14 public function getMethodStatus() { 15 return self::METHOD_STATUS_FROZEN; 16 } 17 18 public function getMethodStatusDescription() { 19 return pht( 20 'This method is frozen and will eventually be deprecated. New code '. 21 'should use "diffusion.commit.search" instead.'); 22 } 23 24 protected function defineReturnType() { 25 return 'map<string, dict>'; 26 } 27 28 protected function defineParamTypes() { 29 return array( 30 'ids' => 'optional list<int>', 31 'phids' => 'optional list<phid>', 32 'names' => 'optional list<string>', 33 'repositoryPHID' => 'optional phid', 34 'needMessages' => 'optional bool', 35 'bypassCache' => 'optional bool', 36 ) + $this->getPagerParamTypes(); 37 } 38 39 protected function execute(ConduitAPIRequest $request) { 40 $need_messages = $request->getValue('needMessages'); 41 $viewer = $request->getUser(); 42 43 $query = id(new DiffusionCommitQuery()) 44 ->setViewer($viewer) 45 ->needCommitData(true); 46 47 $repository_phid = $request->getValue('repositoryPHID'); 48 if ($repository_phid) { 49 $repository = id(new PhabricatorRepositoryQuery()) 50 ->setViewer($viewer) 51 ->withPHIDs(array($repository_phid)) 52 ->executeOne(); 53 if ($repository) { 54 $query->withRepository($repository); 55 } 56 } 57 58 $names = $request->getValue('names'); 59 if ($names) { 60 $query->withIdentifiers($names); 61 } 62 63 $ids = $request->getValue('ids'); 64 if ($ids) { 65 $query->withIDs($ids); 66 } 67 68 $phids = $request->getValue('phids'); 69 if ($phids) { 70 $query->withPHIDs($phids); 71 } 72 73 $pager = $this->newPager($request); 74 $commits = $query->executeWithCursorPager($pager); 75 76 $map = $query->getIdentifierMap(); 77 $map = mpull($map, 'getPHID'); 78 79 $data = array(); 80 foreach ($commits as $commit) { 81 $commit_data = $commit->getCommitData(); 82 83 $uri = $commit->getURI(); 84 $uri = PhabricatorEnv::getProductionURI($uri); 85 86 $dict = array( 87 'id' => $commit->getID(), 88 'phid' => $commit->getPHID(), 89 'repositoryPHID' => $commit->getRepository()->getPHID(), 90 'identifier' => $commit->getCommitIdentifier(), 91 'epoch' => $commit->getEpoch(), 92 'authorEpoch' => $commit_data->getAuthorEpoch(), 93 'uri' => $uri, 94 'isImporting' => !$commit->isImported(), 95 'summary' => $commit->getSummary(), 96 'authorPHID' => $commit->getAuthorPHID(), 97 'committerPHID' => $commit_data->getCommitDetail('committerPHID'), 98 'author' => $commit_data->getAuthorString(), 99 'authorName' => $commit_data->getAuthorDisplayName(), 100 'authorEmail' => $commit_data->getAuthorEmail(), 101 'committer' => $commit_data->getCommitterString(), 102 'committerName' => $commit_data->getCommitterDisplayName(), 103 'committerEmail' => $commit_data->getCommitterEmail(), 104 'hashes' => array(), 105 ); 106 107 if ($need_messages) { 108 $dict['message'] = $commit_data->getCommitMessage(); 109 } 110 111 $data[$commit->getPHID()] = $dict; 112 } 113 114 $result = array( 115 'data' => $data, 116 'identifierMap' => nonempty($map, (object)array()), 117 ); 118 119 return $this->addPagerResults($result, $pager); 120 } 121 122}