@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 recaptime-dev/main 59 lines 1.4 kB view raw
1<?php 2 3final class DiffusionRefsQueryConduitAPIMethod 4 extends DiffusionQueryConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'diffusion.refsquery'; 8 } 9 10 public function getMethodDescription() { 11 return pht( 12 'Query a git repository for ref information at a specific commit.'); 13 } 14 15 protected function defineReturnType() { 16 return 'array'; 17 } 18 19 protected function defineCustomParamTypes() { 20 return array( 21 'commit' => 'required string', 22 ); 23 } 24 25 protected function getGitResult(ConduitAPIRequest $request) { 26 $drequest = $this->getDiffusionRequest(); 27 $repository = $drequest->getRepository(); 28 $commit = $request->getValue('commit'); 29 30 list($stdout) = $repository->execxLocalCommand( 31 'log -n 1 %s %s --', 32 '--format=%d', 33 gitsprintf('%s', $commit)); 34 35 // %d, gives a weird output format 36 // similar to (remote/one, remote/two, remote/three) 37 $refs = trim($stdout, "() \n"); 38 if (!$refs) { 39 return array(); 40 } 41 $refs = explode(',', $refs); 42 $refs = array_map('trim', $refs); 43 44 $ref_links = array(); 45 foreach ($refs as $ref) { 46 $ref_links[] = array( 47 'ref' => $ref, 48 'href' => $drequest->generateURI( 49 array( 50 'action' => 'browse', 51 'branch' => $ref, 52 )), 53 ); 54 } 55 56 return $ref_links; 57 } 58 59}