Summary: Ref T2783. This populates the following fields in DiffusionQueryCommitsConduitAPIMethod using DiffusionLowLevelCommitQuery when `bypassCache` is set to true: * `authorName` * `authorEmail` * `committerName` * `committerEmail` * `message` * `hashes` The original outline called for `authorPHID` and `committerPHID` as well (but no `message` field). As far as I can tell, the PHIDs aren't actual a property on `DiffusionCommitRef`, and since the intention of this is to be able to populate a `DiffusionCommitRef`, I haven't included them. Let me know if we really do need the PHIDs here. Test Plan: Tested using 3 Phabricator instances (one web, one taskmaster and one storage). The web and taskmaster tiers are directed at the Conduit API of the storage tier. Made a `diffusion.querycommits` from the Conduit app on the web tier instance and saw the data populated from the raw VCS data (located on the storage tier). Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Maniphest Tasks: T2783 Differential Revision: https://secure.phabricator.com/D10399
142 lines
3.9 KiB
PHP
142 lines
3.9 KiB
PHP
<?php
|
|
|
|
final class DiffusionQueryCommitsConduitAPIMethod
|
|
extends DiffusionConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'diffusion.querycommits';
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return pht('Retrieve information about commits.');
|
|
}
|
|
|
|
public function defineReturnType() {
|
|
return 'map<string, dict>';
|
|
}
|
|
|
|
public function defineParamTypes() {
|
|
return array(
|
|
'ids' => 'optional list<int>',
|
|
'phids' => 'optional list<phid>',
|
|
'names' => 'optional list<string>',
|
|
'repositoryPHID' => 'optional phid',
|
|
'needMessages' => 'optional bool',
|
|
'bypassCache' => 'optional bool',
|
|
) + $this->getPagerParamTypes();
|
|
}
|
|
|
|
public function defineErrorTypes() {
|
|
return array();
|
|
}
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
$need_messages = $request->getValue('needMessages');
|
|
$bypass_cache = $request->getValue('bypassCache');
|
|
|
|
$query = id(new DiffusionCommitQuery())
|
|
->setViewer($request->getUser());
|
|
|
|
if ($need_messages) {
|
|
$query->needCommitData(true);
|
|
}
|
|
|
|
$repository_phid = $request->getValue('repositoryPHID');
|
|
if ($repository_phid) {
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
->setViewer($request->getUser())
|
|
->withPHIDs(array($repository_phid))
|
|
->executeOne();
|
|
if ($repository) {
|
|
$query->withRepository($repository);
|
|
}
|
|
}
|
|
|
|
$names = $request->getValue('names');
|
|
if ($names) {
|
|
$query->withIdentifiers($names);
|
|
}
|
|
|
|
$ids = $request->getValue('ids');
|
|
if ($ids) {
|
|
$query->withIDs($ids);
|
|
}
|
|
|
|
$phids = $request->getValue('phids');
|
|
if ($phids) {
|
|
$query->withPHIDs($phids);
|
|
}
|
|
|
|
$pager = $this->newPager($request);
|
|
$commits = $query->executeWithCursorPager($pager);
|
|
|
|
$map = $query->getIdentifierMap();
|
|
$map = mpull($map, 'getPHID');
|
|
|
|
$data = array();
|
|
foreach ($commits as $commit) {
|
|
$callsign = $commit->getRepository()->getCallsign();
|
|
$identifier = $commit->getCommitIdentifier();
|
|
$uri = '/r'.$callsign.$identifier;
|
|
$uri = PhabricatorEnv::getProductionURI($uri);
|
|
|
|
$dict = array(
|
|
'id' => $commit->getID(),
|
|
'phid' => $commit->getPHID(),
|
|
'repositoryPHID' => $commit->getRepository()->getPHID(),
|
|
'identifier' => $identifier,
|
|
'epoch' => $commit->getEpoch(),
|
|
'uri' => $uri,
|
|
'isImporting' => !$commit->isImported(),
|
|
'summary' => $commit->getSummary(),
|
|
'authorName' => '',
|
|
'authorEmail' => '',
|
|
'committerName' => '',
|
|
'committerEmail' => '',
|
|
'hashes' => array(),
|
|
);
|
|
|
|
if ($bypass_cache) {
|
|
$lowlevel_commitref = id(new DiffusionLowLevelCommitQuery())
|
|
->setRepository($commit->getRepository())
|
|
->withIdentifier($commit->getCommitIdentifier())
|
|
->execute();
|
|
|
|
$dict['authorName'] = $lowlevel_commitref->getAuthorName();
|
|
$dict['authorEmail'] = $lowlevel_commitref->getAuthorEmail();
|
|
$dict['committerName'] = $lowlevel_commitref->getCommitterName();
|
|
$dict['committerEmail'] = $lowlevel_commitref->getCommitterEmail();
|
|
|
|
if ($need_messages) {
|
|
$dict['message'] = $lowlevel_commitref->getMessage();
|
|
}
|
|
|
|
foreach ($lowlevel_commitref->getHashes() as $hash) {
|
|
$dict['hashes'][] = array(
|
|
'type' => $hash->getHashType(),
|
|
'value' => $hash->getHashValue());
|
|
}
|
|
}
|
|
|
|
if ($need_messages) {
|
|
$commit_data = $commit->getCommitData();
|
|
if ($commit_data) {
|
|
$dict['message'] = $commit_data->getCommitMessage();
|
|
} else {
|
|
$dict['message'] = null;
|
|
}
|
|
}
|
|
|
|
$data[$commit->getPHID()] = $dict;
|
|
}
|
|
|
|
$result = array(
|
|
'data' => $data,
|
|
'identifierMap' => nonempty($map, (object)array()),
|
|
);
|
|
|
|
return $this->addPagerResults($result, $pager);
|
|
}
|
|
|
|
}
|