[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/conduit/ -> DiffusionQueryCommitsConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final 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 defineReturnType() {
  15      return 'map<string, dict>';
  16    }
  17  
  18    public function defineParamTypes() {
  19      return array(
  20        'ids'               => 'optional list<int>',
  21        'phids'             => 'optional list<phid>',
  22        'names'             => 'optional list<string>',
  23        'repositoryPHID'    => 'optional phid',
  24        'needMessages'      => 'optional bool',
  25        'bypassCache'       => 'optional bool',
  26      ) + $this->getPagerParamTypes();
  27    }
  28  
  29    public function defineErrorTypes() {
  30      return array();
  31    }
  32  
  33    protected function execute(ConduitAPIRequest $request) {
  34      $need_messages = $request->getValue('needMessages');
  35      $bypass_cache = $request->getValue('bypassCache');
  36  
  37      $query = id(new DiffusionCommitQuery())
  38        ->setViewer($request->getUser())
  39        ->needCommitData(true);
  40  
  41      $repository_phid = $request->getValue('repositoryPHID');
  42      if ($repository_phid) {
  43        $repository = id(new PhabricatorRepositoryQuery())
  44          ->setViewer($request->getUser())
  45          ->withPHIDs(array($repository_phid))
  46          ->executeOne();
  47        if ($repository) {
  48          $query->withRepository($repository);
  49        }
  50      }
  51  
  52      $names = $request->getValue('names');
  53      if ($names) {
  54        $query->withIdentifiers($names);
  55      }
  56  
  57      $ids = $request->getValue('ids');
  58      if ($ids) {
  59        $query->withIDs($ids);
  60      }
  61  
  62      $phids = $request->getValue('phids');
  63      if ($phids) {
  64        $query->withPHIDs($phids);
  65      }
  66  
  67      $pager = $this->newPager($request);
  68      $commits = $query->executeWithCursorPager($pager);
  69  
  70      $map = $query->getIdentifierMap();
  71      $map = mpull($map, 'getPHID');
  72  
  73      $data = array();
  74      foreach ($commits as $commit) {
  75        $commit_data = $commit->getCommitData();
  76  
  77        $callsign = $commit->getRepository()->getCallsign();
  78        $identifier = $commit->getCommitIdentifier();
  79        $uri = '/r'.$callsign.$identifier;
  80        $uri = PhabricatorEnv::getProductionURI($uri);
  81  
  82        $dict = array(
  83          'id' => $commit->getID(),
  84          'phid' => $commit->getPHID(),
  85          'repositoryPHID' => $commit->getRepository()->getPHID(),
  86          'identifier' => $identifier,
  87          'epoch' => $commit->getEpoch(),
  88          'uri' => $uri,
  89          'isImporting' => !$commit->isImported(),
  90          'summary' => $commit->getSummary(),
  91          'authorPHID' => $commit->getAuthorPHID(),
  92          'committerPHID' => $commit_data->getCommitDetail('committerPHID'),
  93          'author' => $commit_data->getAuthorName(),
  94          'authorName' => $commit_data->getCommitDetail('authorName'),
  95          'authorEmail' => $commit_data->getCommitDetail('authorEmail'),
  96          'committer' => $commit_data->getCommitDetail('committer'),
  97          'committerName' => $commit_data->getCommitDetail('committerName'),
  98          'committerEmail' => $commit_data->getCommitDetail('committerEmail'),
  99          'hashes' => array(),
 100        );
 101  
 102        if ($bypass_cache) {
 103          $lowlevel_commitref = id(new DiffusionLowLevelCommitQuery())
 104            ->setRepository($commit->getRepository())
 105            ->withIdentifier($commit->getCommitIdentifier())
 106            ->execute();
 107  
 108          $dict['author'] = $lowlevel_commitref->getAuthor();
 109          $dict['authorName'] = $lowlevel_commitref->getAuthorName();
 110          $dict['authorEmail'] = $lowlevel_commitref->getAuthorEmail();
 111          $dict['committer'] = $lowlevel_commitref->getCommitter();
 112          $dict['committerName'] = $lowlevel_commitref->getCommitterName();
 113          $dict['committerEmail'] = $lowlevel_commitref->getCommitterEmail();
 114  
 115          if ($need_messages) {
 116            $dict['message'] = $lowlevel_commitref->getMessage();
 117          }
 118  
 119          foreach ($lowlevel_commitref->getHashes() as $hash) {
 120            $dict['hashes'][] = array(
 121              'type' => $hash->getHashType(),
 122              'value' => $hash->getHashValue(),
 123            );
 124          }
 125        }
 126  
 127        if ($need_messages && !$bypass_cache) {
 128          $dict['message'] = $commit_data->getCommitMessage();
 129        }
 130  
 131        $data[$commit->getPHID()] = $dict;
 132      }
 133  
 134      $result = array(
 135        'data' => $data,
 136        'identifierMap' => nonempty($map, (object)array()),
 137      );
 138  
 139      return $this->addPagerResults($result, $pager);
 140    }
 141  
 142  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1