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 $reviewers = array();
|
||||||
private $revIDs = array();
|
private $revIDs = array();
|
||||||
private $commitHashes = array();
|
private $commitHashes = array();
|
||||||
|
private $commitPHIDs = array();
|
||||||
private $phids = array();
|
private $phids = array();
|
||||||
private $responsibles = array();
|
private $responsibles = array();
|
||||||
private $branches = array();
|
private $branches = array();
|
||||||
|
@ -153,6 +154,20 @@ final class DifferentialRevisionQuery
|
||||||
return $this;
|
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,
|
* Filter results to revisions with a given status. Provide a class constant,
|
||||||
* such as `DifferentialRevisionQuery::STATUS_OPEN`.
|
* such as `DifferentialRevisionQuery::STATUS_OPEN`.
|
||||||
|
@ -653,6 +668,13 @@ final class DifferentialRevisionQuery
|
||||||
$this->draftAuthors);
|
$this->draftAuthors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->commitPHIDs) {
|
||||||
|
$joins[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'JOIN %T commits ON commits.revisionID = r.id',
|
||||||
|
DifferentialRevision::TABLE_COMMIT);
|
||||||
|
}
|
||||||
|
|
||||||
$joins = implode(' ', $joins);
|
$joins = implode(' ', $joins);
|
||||||
|
|
||||||
return $joins;
|
return $joins;
|
||||||
|
@ -714,6 +736,13 @@ final class DifferentialRevisionQuery
|
||||||
$where[] = $hash_clauses;
|
$where[] = $hash_clauses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->commitPHIDs) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'commits.commitPHID IN (%Ls)',
|
||||||
|
$this->commitPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->phids) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
|
|
|
@ -135,7 +135,7 @@ final class DiffusionGetCommitsConduitAPIMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
$commits = $this->addRepositoryCommitDataInformation($commits);
|
$commits = $this->addRepositoryCommitDataInformation($commits);
|
||||||
$commits = $this->addDifferentialInformation($commits);
|
$commits = $this->addDifferentialInformation($commits, $request);
|
||||||
$commits = $this->addManiphestInformation($commits);
|
$commits = $this->addManiphestInformation($commits);
|
||||||
|
|
||||||
foreach ($commits as $name => $commit) {
|
foreach ($commits as $name => $commit) {
|
||||||
|
@ -238,31 +238,29 @@ final class DiffusionGetCommitsConduitAPIMethod
|
||||||
/**
|
/**
|
||||||
* Enhance the commit list with Differential information.
|
* Enhance the commit list with Differential information.
|
||||||
*/
|
*/
|
||||||
private function addDifferentialInformation(array $commits) {
|
private function addDifferentialInformation(
|
||||||
|
array $commits,
|
||||||
|
ConduitAPIRequest $request) {
|
||||||
|
|
||||||
$commit_phids = ipull($commits, 'commitPHID');
|
$commit_phids = ipull($commits, 'commitPHID');
|
||||||
|
|
||||||
// TODO: (T603) This should be policy checked, either by moving to
|
$revisions = id(new DifferentialRevisionQuery())
|
||||||
// DifferentialRevisionQuery or by doing a followup query to make sure
|
->setViewer($request->getUser())
|
||||||
// the matched objects are visible.
|
->withCommitPHIDs($commit_phids)
|
||||||
|
->needCommitPHIDs(true)
|
||||||
$rev_conn_r = id(new DifferentialRevision())->establishConnection('r');
|
->execute();
|
||||||
$revs = queryfx_all(
|
$rev_phid_commit_phids_map = mpull($revisions, 'getCommitPHIDs', 'getPHID');
|
||||||
$rev_conn_r,
|
$revisions = mpull($revisions, null, 'getPHID');
|
||||||
'SELECT r.id id, r.phid phid, c.commitPHID commitPHID FROM %T r JOIN %T c
|
foreach ($rev_phid_commit_phids_map as $rev_phid => $commit_phids) {
|
||||||
ON r.id = c.revisionID
|
foreach ($commits as $name => $commit) {
|
||||||
WHERE c.commitPHID in (%Ls)',
|
$commit_phid = $commit['commitPHID'];
|
||||||
id(new DifferentialRevision())->getTableName(),
|
if (in_array($commit_phid, $commit_phids)) {
|
||||||
DifferentialRevision::TABLE_COMMIT,
|
$revision = $revisions[$rev_phid];
|
||||||
$commit_phids);
|
$commits[$name] += array(
|
||||||
|
'differentialRevisionID' => 'D'.$revision->getID(),
|
||||||
$revs = ipull($revs, null, 'commitPHID');
|
'differentialRevisionPHID' => $revision->getPHID(),
|
||||||
foreach ($commits as $name => $commit) {
|
);
|
||||||
if (isset($revs[$commit['commitPHID']])) {
|
}
|
||||||
$rev = $revs[$commit['commitPHID']];
|
|
||||||
$commits[$name] += array(
|
|
||||||
'differentialRevisionID' => 'D'.$rev['id'],
|
|
||||||
'differentialRevisionPHID' => $rev['phid'],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue