mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
Policy - clean up the deprecated diffusion.getcommits
Summary: Ref T7094. Could just delete this end point too I guess? Needed to add "withCommitPHIDs" to the differentialrevisionquery to get this done. Test Plan: used diffusion.getcommits from conduit console and got a sensible result for a query for two commits, one with a diff and one without. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7094 Differential Revision: https://secure.phabricator.com/D11581
This commit is contained in:
parent
d804598f17
commit
bdb3adeee4
2 changed files with 51 additions and 24 deletions
|
@ -32,6 +32,7 @@ final class DifferentialRevisionQuery
|
|||
private $reviewers = array();
|
||||
private $revIDs = array();
|
||||
private $commitHashes = array();
|
||||
private $commitPHIDs = array();
|
||||
private $phids = array();
|
||||
private $responsibles = array();
|
||||
private $branches = array();
|
||||
|
@ -153,6 +154,20 @@ final class DifferentialRevisionQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter results to revisions that have one of the provided PHIDs as
|
||||
* commits. Calling this function will clear anything set by previous calls
|
||||
* to @{method:withCommitPHIDs}.
|
||||
*
|
||||
* @param array List of PHIDs of commits
|
||||
* @return this
|
||||
* @task config
|
||||
*/
|
||||
public function withCommitPHIDs(array $commit_phids) {
|
||||
$this->commitPHIDs = $commit_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter results to revisions with a given status. Provide a class constant,
|
||||
* such as `DifferentialRevisionQuery::STATUS_OPEN`.
|
||||
|
@ -653,6 +668,13 @@ final class DifferentialRevisionQuery
|
|||
$this->draftAuthors);
|
||||
}
|
||||
|
||||
if ($this->commitPHIDs) {
|
||||
$joins[] = qsprintf(
|
||||
$conn_r,
|
||||
'JOIN %T commits ON commits.revisionID = r.id',
|
||||
DifferentialRevision::TABLE_COMMIT);
|
||||
}
|
||||
|
||||
$joins = implode(' ', $joins);
|
||||
|
||||
return $joins;
|
||||
|
@ -714,6 +736,13 @@ final class DifferentialRevisionQuery
|
|||
$where[] = $hash_clauses;
|
||||
}
|
||||
|
||||
if ($this->commitPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'commits.commitPHID IN (%Ls)',
|
||||
$this->commitPHIDs);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
|
|
|
@ -135,7 +135,7 @@ final class DiffusionGetCommitsConduitAPIMethod
|
|||
}
|
||||
|
||||
$commits = $this->addRepositoryCommitDataInformation($commits);
|
||||
$commits = $this->addDifferentialInformation($commits);
|
||||
$commits = $this->addDifferentialInformation($commits, $request);
|
||||
$commits = $this->addManiphestInformation($commits);
|
||||
|
||||
foreach ($commits as $name => $commit) {
|
||||
|
@ -238,33 +238,31 @@ final class DiffusionGetCommitsConduitAPIMethod
|
|||
/**
|
||||
* Enhance the commit list with Differential information.
|
||||
*/
|
||||
private function addDifferentialInformation(array $commits) {
|
||||
private function addDifferentialInformation(
|
||||
array $commits,
|
||||
ConduitAPIRequest $request) {
|
||||
|
||||
$commit_phids = ipull($commits, 'commitPHID');
|
||||
|
||||
// TODO: (T603) This should be policy checked, either by moving to
|
||||
// DifferentialRevisionQuery or by doing a followup query to make sure
|
||||
// the matched objects are visible.
|
||||
|
||||
$rev_conn_r = id(new DifferentialRevision())->establishConnection('r');
|
||||
$revs = queryfx_all(
|
||||
$rev_conn_r,
|
||||
'SELECT r.id id, r.phid phid, c.commitPHID commitPHID FROM %T r JOIN %T c
|
||||
ON r.id = c.revisionID
|
||||
WHERE c.commitPHID in (%Ls)',
|
||||
id(new DifferentialRevision())->getTableName(),
|
||||
DifferentialRevision::TABLE_COMMIT,
|
||||
$commit_phids);
|
||||
|
||||
$revs = ipull($revs, null, 'commitPHID');
|
||||
$revisions = id(new DifferentialRevisionQuery())
|
||||
->setViewer($request->getUser())
|
||||
->withCommitPHIDs($commit_phids)
|
||||
->needCommitPHIDs(true)
|
||||
->execute();
|
||||
$rev_phid_commit_phids_map = mpull($revisions, 'getCommitPHIDs', 'getPHID');
|
||||
$revisions = mpull($revisions, null, 'getPHID');
|
||||
foreach ($rev_phid_commit_phids_map as $rev_phid => $commit_phids) {
|
||||
foreach ($commits as $name => $commit) {
|
||||
if (isset($revs[$commit['commitPHID']])) {
|
||||
$rev = $revs[$commit['commitPHID']];
|
||||
$commit_phid = $commit['commitPHID'];
|
||||
if (in_array($commit_phid, $commit_phids)) {
|
||||
$revision = $revisions[$rev_phid];
|
||||
$commits[$name] += array(
|
||||
'differentialRevisionID' => 'D'.$rev['id'],
|
||||
'differentialRevisionPHID' => $rev['phid'],
|
||||
'differentialRevisionID' => 'D'.$revision->getID(),
|
||||
'differentialRevisionPHID' => $revision->getPHID(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $commits;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue