mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-02 02:40:58 +01:00
Methods for reading reviewers from edges in differential
Summary: Add `getReviewerStatus` to get an array of `DifferentialReviewer` objects. The method `needReviewerStatus` in `DifferentialRevisionQuery` loads the edges into the revisions loaded. Test Plan: Added `->needReviewerStatus(true)` to `DifferentialRevisionSearchEngine` and checked through logging that the data was being loaded correctly. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D6450
This commit is contained in:
parent
1b48e922d4
commit
d4c28dcbc2
4 changed files with 105 additions and 0 deletions
|
@ -395,6 +395,7 @@ phutil_register_library_map(array(
|
||||||
'DifferentialRevertPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php',
|
'DifferentialRevertPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php',
|
||||||
'DifferentialReviewRequestMail' => 'applications/differential/mail/DifferentialReviewRequestMail.php',
|
'DifferentialReviewRequestMail' => 'applications/differential/mail/DifferentialReviewRequestMail.php',
|
||||||
'DifferentialReviewedByFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewedByFieldSpecification.php',
|
'DifferentialReviewedByFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewedByFieldSpecification.php',
|
||||||
|
'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php',
|
||||||
'DifferentialReviewerStatus' => 'applications/differential/constants/DifferentialReviewerStatus.php',
|
'DifferentialReviewerStatus' => 'applications/differential/constants/DifferentialReviewerStatus.php',
|
||||||
'DifferentialReviewersFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewersFieldSpecification.php',
|
'DifferentialReviewersFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewersFieldSpecification.php',
|
||||||
'DifferentialRevision' => 'applications/differential/storage/DifferentialRevision.php',
|
'DifferentialRevision' => 'applications/differential/storage/DifferentialRevision.php',
|
||||||
|
|
|
@ -56,6 +56,7 @@ final class DifferentialRevisionQuery
|
||||||
private $needDiffIDs = false;
|
private $needDiffIDs = false;
|
||||||
private $needCommitPHIDs = false;
|
private $needCommitPHIDs = false;
|
||||||
private $needHashes = false;
|
private $needHashes = false;
|
||||||
|
private $needReviewerStatus = false;
|
||||||
|
|
||||||
private $buildingGlobalOrder;
|
private $buildingGlobalOrder;
|
||||||
|
|
||||||
|
@ -326,6 +327,19 @@ final class DifferentialRevisionQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether or not the query should load associated reviewer status.
|
||||||
|
*
|
||||||
|
* @param bool True to load and attach reviewers.
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function needReviewerStatus($need_reviewer_status) {
|
||||||
|
$this->needReviewerStatus = $need_reviewer_status;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Query Execution )---------------------------------------------------- */
|
/* -( Query Execution )---------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -376,6 +390,10 @@ final class DifferentialRevisionQuery
|
||||||
$this->loadHashes($conn_r, $revisions);
|
$this->loadHashes($conn_r, $revisions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->needReviewerStatus) {
|
||||||
|
$this->loadReviewers($conn_r, $revisions);
|
||||||
|
}
|
||||||
|
|
||||||
return $revisions;
|
return $revisions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,6 +921,37 @@ final class DifferentialRevisionQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadReviewers(
|
||||||
|
AphrontDatabaseConnection $conn_r,
|
||||||
|
array $revisions) {
|
||||||
|
|
||||||
|
assert_instances_of($revisions, 'DifferentialRevision');
|
||||||
|
$edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER;
|
||||||
|
|
||||||
|
$edges = id(new PhabricatorEdgeQuery())
|
||||||
|
->withSourcePHIDs(mpull($revisions, 'getPHID'))
|
||||||
|
->withEdgeTypes(array($edge_type))
|
||||||
|
->needEdgeData(true)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
foreach ($revisions as $revision) {
|
||||||
|
$revision_edges = $edges[$revision->getPHID()][$edge_type];
|
||||||
|
|
||||||
|
$reviewers = array();
|
||||||
|
foreach ($revision_edges as $user_phid => $edge) {
|
||||||
|
$data = $edge['data'];
|
||||||
|
$reviewers[] = new DifferentialReviewer(
|
||||||
|
$user_phid, $data['status'], idx($data, 'diff', null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$revision->attachReviewerStatus($reviewers);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static function splitResponsible(array $revisions, array $user_phids) {
|
public static function splitResponsible(array $revisions, array $user_phids) {
|
||||||
$blocking = array();
|
$blocking = array();
|
||||||
$active = array();
|
$active = array();
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DifferentialReviewer {
|
||||||
|
|
||||||
|
protected $reviewerPHID;
|
||||||
|
protected $status;
|
||||||
|
protected $diffID;
|
||||||
|
|
||||||
|
public function __construct($reviewer_phid, $status, $diff_id = null) {
|
||||||
|
$this->reviewerPHID = $reviewer_phid;
|
||||||
|
$this->setStatus($status, $diff_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReviewerPHID() {
|
||||||
|
return $this->reviewerPHID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus() {
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDiffID() {
|
||||||
|
return $this->diffID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status, $diff_id = null) {
|
||||||
|
if ($status == DifferentialReviewerStatus::STATUS_REJECTED
|
||||||
|
&& $diff_id === null) {
|
||||||
|
|
||||||
|
throw new Exception('STATUS_REJECTED must have a diff_id set');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->status = $status;
|
||||||
|
$this->diffID = $diff_id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ final class DifferentialRevision extends DifferentialDAO
|
||||||
private $diffIDs;
|
private $diffIDs;
|
||||||
private $hashes;
|
private $hashes;
|
||||||
|
|
||||||
|
private $reviewerStatus;
|
||||||
|
|
||||||
const RELATIONSHIP_TABLE = 'differential_relationship';
|
const RELATIONSHIP_TABLE = 'differential_relationship';
|
||||||
const TABLE_COMMIT = 'differential_commit';
|
const TABLE_COMMIT = 'differential_commit';
|
||||||
|
@ -335,4 +336,19 @@ final class DifferentialRevision extends DifferentialDAO
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getReviewerStatus() {
|
||||||
|
if ($this->reviewerStatus === null) {
|
||||||
|
throw new Exception(
|
||||||
|
"Call attachReviewerStatus() before getReviewerStatus()!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $this->reviewerStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachReviewerStatus(array $reviewers) {
|
||||||
|
assert_instances_of($reviewers, 'DifferentialReviewer');
|
||||||
|
|
||||||
|
$this->reviewerStatus = $reviewers;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue