Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
| <?php | <?php | ||||
| final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter { | final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter { | ||||
| private $changesets; | private $changesets; | ||||
| private $commitRef; | private $commitRef; | ||||
| private $fields; | private $fields; | ||||
| private $revision = false; | private $revision = false; | ||||
| private $affectedPackages; | private $affectedPackages; | ||||
| private $identityCache = array(); | |||||
| public function getAdapterContentName() { | public function getAdapterContentName() { | ||||
| return pht('Commit Hook: Commit Content'); | return pht('Commit Hook: Commit Content'); | ||||
| } | } | ||||
| public function getAdapterSortOrder() { | public function getAdapterSortOrder() { | ||||
| return 2500; | return 2500; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | switch ($vcs) { | ||||
| } | } | ||||
| return $ref->getAuthor(); | return $ref->getAuthor(); | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | ||||
| // In Subversion, the pusher is always the committer. | // In Subversion, the pusher is always the committer. | ||||
| return $this->getHookEngine()->getViewer()->getUsername(); | return $this->getHookEngine()->getViewer()->getUsername(); | ||||
| } | } | ||||
| } | } | ||||
| private function lookupUser($author) { | private function lookupUser($raw_identity) { | ||||
| return id(new DiffusionResolveUserQuery()) | // See T13480. After the move to repository identities, we want to look | ||||
| ->withName($author) | // users up in the identity table. If you push a commit which is authored | ||||
| ->execute(); | // by "A Duck <duck@example.org>" and that identity is bound to user | ||||
| // "@mallard" in the identity table, Herald should see the author of the | |||||
| // commit as "@mallard" when evaluating pre-commit content rules. | |||||
| if (!array_key_exists($raw_identity, $this->identityCache)) { | |||||
| $repository = $this->getHookEngine()->getRepository(); | |||||
| $viewer = $this->getHookEngine()->getViewer(); | |||||
| $identity_engine = id(new DiffusionRepositoryIdentityEngine()) | |||||
| ->setViewer($viewer); | |||||
| // We must provide a "sourcePHID" when resolving identities, but don't | |||||
| // have a legitimate one yet. Just use the repository PHID as a | |||||
| // reasonable value. This won't actually be written to storage. | |||||
| $source_phid = $repository->getPHID(); | |||||
| $identity_engine->setSourcePHID($source_phid); | |||||
| // If the identity doesn't exist yet, we don't want to create it if | |||||
| // we haven't seen it before. It will be created later when we actually | |||||
| // import the commit. | |||||
| $identity_engine->setDryRun(true); | |||||
| $author_identity = $identity_engine->newResolvedIdentity($raw_identity); | |||||
| $effective_phid = $author_identity->getCurrentEffectiveUserPHID(); | |||||
| $this->identityCache[$raw_identity] = $effective_phid; | |||||
| } | |||||
| return $this->identityCache[$raw_identity]; | |||||
| } | } | ||||
| private function getCommitFields() { | private function getCommitFields() { | ||||
| if ($this->fields === null) { | if ($this->fields === null) { | ||||
| $this->fields = id(new DiffusionLowLevelCommitFieldsQuery()) | $this->fields = id(new DiffusionLowLevelCommitFieldsQuery()) | ||||
| ->setRepository($this->getHookEngine()->getRepository()) | ->setRepository($this->getHookEngine()->getRepository()) | ||||
| ->withCommitRef($this->getCommitRef()) | ->withCommitRef($this->getCommitRef()) | ||||
| ->execute(); | ->execute(); | ||||
| ▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines | |||||