[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephCommitFinder { 4 5 private $releephProject; 6 private $user; 7 private $objectPHID; 8 9 public function setUser(PhabricatorUser $user) { 10 $this->user = $user; 11 return $this; 12 } 13 public function getUser() { 14 return $this->user; 15 } 16 17 public function setReleephProject(ReleephProject $rp) { 18 $this->releephProject = $rp; 19 return $this; 20 } 21 22 public function getRequestedObjectPHID() { 23 return $this->objectPHID; 24 } 25 26 public function fromPartial($partial_string) { 27 $this->objectPHID = null; 28 29 // Look for diffs 30 $matches = array(); 31 if (preg_match('/^D([1-9]\d*)$/', $partial_string, $matches)) { 32 $diff_id = $matches[1]; 33 // TOOD: (T603) This is all slated for annihilation. 34 $diff_rev = id(new DifferentialRevision())->load($diff_id); 35 if (!$diff_rev) { 36 throw new ReleephCommitFinderException( 37 "{$partial_string} does not refer to an existing diff."); 38 } 39 $commit_phids = $diff_rev->loadCommitPHIDs(); 40 41 if (!$commit_phids) { 42 throw new ReleephCommitFinderException( 43 "{$partial_string} has no commits associated with it yet."); 44 } 45 46 $this->objectPHID = $diff_rev->getPHID(); 47 48 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 49 'phid IN (%Ls) ORDER BY epoch ASC', 50 $commit_phids); 51 return head($commits); 52 } 53 54 // Look for a raw commit number, or r<callsign><commit-number>. 55 $repository = $this->releephProject->getRepository(); 56 $dr_data = null; 57 $matches = array(); 58 if (preg_match('/^r(?P<callsign>[A-Z]+)(?P<commit>\w+)$/', 59 $partial_string, $matches)) { 60 $callsign = $matches['callsign']; 61 if ($callsign != $repository->getCallsign()) { 62 throw new ReleephCommitFinderException(sprintf( 63 '%s is in a different repository to this Releeph project (%s).', 64 $partial_string, 65 $repository->getCallsign())); 66 } else { 67 $dr_data = $matches; 68 } 69 } else { 70 $dr_data = array( 71 'callsign' => $repository->getCallsign(), 72 'commit' => $partial_string, 73 ); 74 } 75 76 try { 77 $dr_data['user'] = $this->getUser(); 78 $dr = DiffusionRequest::newFromDictionary($dr_data); 79 } catch (Exception $ex) { 80 $message = "No commit matches {$partial_string}: ".$ex->getMessage(); 81 throw new ReleephCommitFinderException($message); 82 } 83 84 $phabricator_repository_commit = $dr->loadCommit(); 85 86 if (!$phabricator_repository_commit) { 87 throw new ReleephCommitFinderException( 88 "The commit {$partial_string} doesn't exist in this repository."); 89 } 90 91 // When requesting a single commit, if it has an associated review we 92 // imply the review was requested instead. This is always correct for now 93 // and consistent with the older behavior, although it might not be the 94 // right rule in the future. 95 $phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 96 $phabricator_repository_commit->getPHID(), 97 PhabricatorEdgeConfig::TYPE_COMMIT_HAS_DREV); 98 if ($phids) { 99 $this->objectPHID = head($phids); 100 } 101 102 return $phabricator_repository_commit; 103 } 104 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |