mirror of
https://we.phorge.it/source/phorge.git
synced 2025-04-09 02:48:41 +02:00
Attach identities to commits and users to identities
Summary: Ref T12164. Make it easier to work with identity objects by attaching them to commits and attaching users to identities. Test Plan: Loaded some commits with `->needIdentities(true)` and checked the resulting objects. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T12164 Differential Revision: https://secure.phabricator.com/D19491
This commit is contained in:
parent
787c59744b
commit
05f333dfba
5 changed files with 74 additions and 3 deletions
|
@ -26,6 +26,7 @@ final class DiffusionCommitQuery
|
||||||
|
|
||||||
private $needCommitData;
|
private $needCommitData;
|
||||||
private $needDrafts;
|
private $needDrafts;
|
||||||
|
private $needIdentities;
|
||||||
|
|
||||||
private $mustFilterRefs = false;
|
private $mustFilterRefs = false;
|
||||||
private $refRepository;
|
private $refRepository;
|
||||||
|
@ -110,6 +111,11 @@ final class DiffusionCommitQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function needIdentities($need) {
|
||||||
|
$this->needIdentities = $need;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function needAuditRequests($need) {
|
public function needAuditRequests($need) {
|
||||||
$this->needAuditRequests = $need;
|
$this->needAuditRequests = $need;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -393,6 +399,24 @@ final class DiffusionCommitQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->needIdentities) {
|
||||||
|
$identity_phids = array_merge(
|
||||||
|
mpull($commits, 'getAuthorIdentityPHID'),
|
||||||
|
mpull($commits, 'getCommitterIdentityPHID'));
|
||||||
|
|
||||||
|
$data = id(new PhabricatorRepositoryIdentityQuery())
|
||||||
|
->withPHIDs($identity_phids)
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->execute();
|
||||||
|
$data = mpull($data, null, 'getPHID');
|
||||||
|
|
||||||
|
foreach ($commits as $commit) {
|
||||||
|
$author_identity = idx($data, $commit->getAuthorIdentityPHID());
|
||||||
|
$committer_identity = idx($data, $commit->getCommitterIdentityPHID());
|
||||||
|
$commit->attachIdentities($author_identity, $committer_identity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->needDrafts) {
|
if ($this->needDrafts) {
|
||||||
PhabricatorDraftEngine::attachDrafts(
|
PhabricatorDraftEngine::attachDrafts(
|
||||||
$viewer,
|
$viewer,
|
||||||
|
|
|
@ -28,6 +28,18 @@ final class PhabricatorRepositoryIdentityPHIDType
|
||||||
public function loadHandles(
|
public function loadHandles(
|
||||||
PhabricatorHandleQuery $query,
|
PhabricatorHandleQuery $query,
|
||||||
array $handles,
|
array $handles,
|
||||||
array $objects) {}
|
array $objects) {
|
||||||
|
|
||||||
|
foreach ($handles as $phid => $handle) {
|
||||||
|
$identity = $objects[$phid];
|
||||||
|
|
||||||
|
$id = $identity->getID();
|
||||||
|
$name = $identity->getIdentityNameRaw();
|
||||||
|
|
||||||
|
$handle->setObjectName(pht('Identity %d', $id));
|
||||||
|
$handle->setName($name);
|
||||||
|
$handle->setURI($identity->getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,10 @@ final class PhabricatorRepositoryIdentityQuery
|
||||||
return $identities;
|
return $identities;
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = id(new PhabricatorUser())->loadAllWhere(
|
$users = id(new PhabricatorPeopleQuery())
|
||||||
'phid IN (%Ls)', $user_ids);
|
->withPHIDs($user_ids)
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->execute();
|
||||||
$users = mpull($users, null, 'getPHID');
|
$users = mpull($users, null, 'getPHID');
|
||||||
|
|
||||||
foreach ($identities as $identity) {
|
foreach ($identities as $identity) {
|
||||||
|
|
|
@ -44,6 +44,9 @@ final class PhabricatorRepositoryCommit
|
||||||
private $audits = self::ATTACHABLE;
|
private $audits = self::ATTACHABLE;
|
||||||
private $repository = self::ATTACHABLE;
|
private $repository = self::ATTACHABLE;
|
||||||
private $customFields = self::ATTACHABLE;
|
private $customFields = self::ATTACHABLE;
|
||||||
|
private $authorIdentity = self::ATTACHABLE;
|
||||||
|
private $committerIdentity = self::ATTACHABLE;
|
||||||
|
|
||||||
private $drafts = array();
|
private $drafts = array();
|
||||||
private $auditAuthorityPHIDs = array();
|
private $auditAuthorityPHIDs = array();
|
||||||
|
|
||||||
|
@ -191,6 +194,21 @@ final class PhabricatorRepositoryCommit
|
||||||
return ($this->audits !== self::ATTACHABLE);
|
return ($this->audits !== self::ATTACHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachIdentities(
|
||||||
|
PhabricatorRepositoryIdentity $author,
|
||||||
|
$committer = null) {
|
||||||
|
$this->authorIdentity = $author;
|
||||||
|
$this->committerIdentity = $committer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthorIdentity() {
|
||||||
|
return $this->assertAttached($this->authorIdentity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommiterIdentity() {
|
||||||
|
return $this->assertAttached($this->committerIdentity);
|
||||||
|
}
|
||||||
|
|
||||||
public function loadAndAttachAuditAuthority(
|
public function loadAndAttachAuditAuthority(
|
||||||
PhabricatorUser $viewer,
|
PhabricatorUser $viewer,
|
||||||
$actor_phid = null) {
|
$actor_phid = null) {
|
||||||
|
|
|
@ -14,6 +14,17 @@ final class PhabricatorRepositoryIdentity
|
||||||
protected $manuallySetUserPHID;
|
protected $manuallySetUserPHID;
|
||||||
protected $currentEffectiveUserPHID;
|
protected $currentEffectiveUserPHID;
|
||||||
|
|
||||||
|
private $effectiveUser = self::ATTACHABLE;
|
||||||
|
|
||||||
|
public function attachEffectiveUser(PhabricatorUser $user) {
|
||||||
|
$this->effectiveUser = $user;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEffectiveUser() {
|
||||||
|
return $this->assertAttached($this->effectiveUser);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getConfiguration() {
|
protected function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
@ -63,6 +74,10 @@ final class PhabricatorRepositoryIdentity
|
||||||
return '/diffusion/identity/view/'.$this->getID().'/';
|
return '/diffusion/identity/view/'.$this->getID().'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasEffectiveUser() {
|
||||||
|
return ($this->currentEffectiveUserPHID != null);
|
||||||
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
if ($this->manuallySetUserPHID) {
|
if ($this->manuallySetUserPHID) {
|
||||||
$this->currentEffectiveUserPHID = $this->manuallySetUserPHID;
|
$this->currentEffectiveUserPHID = $this->manuallySetUserPHID;
|
||||||
|
|
Loading…
Add table
Reference in a new issue