Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
| <?php | <?php | ||||
| /** | /** | ||||
| * @task config Configuring the Hook Engine | * @task config Configuring the Hook Engine | ||||
| * @task hook Hook Execution | * @task hook Hook Execution | ||||
| * @task git Git Hooks | * @task git Git Hooks | ||||
| * @task hg Mercurial Hooks | * @task hg Mercurial Hooks | ||||
| * @task svn Subversion Hooks | * @task svn Subversion Hooks | ||||
| * @task internal Internals | * @task internal Internals | ||||
| */ | */ | ||||
| final class DiffusionCommitHookEngine extends Phobject { | final class DiffusionCommitHookEngine extends Phobject { | ||||
| const ENV_REPOSITORY = 'PHABRICATOR_REPOSITORY'; | const ENV_REPOSITORY = 'PHABRICATOR_REPOSITORY'; | ||||
| const ENV_USER = 'PHABRICATOR_USER'; | const ENV_USER = 'PHABRICATOR_USER'; | ||||
| const ENV_REQUEST = 'PHABRICATOR_REQUEST'; | |||||
| const ENV_REMOTE_ADDRESS = 'PHABRICATOR_REMOTE_ADDRESS'; | const ENV_REMOTE_ADDRESS = 'PHABRICATOR_REMOTE_ADDRESS'; | ||||
| const ENV_REMOTE_PROTOCOL = 'PHABRICATOR_REMOTE_PROTOCOL'; | const ENV_REMOTE_PROTOCOL = 'PHABRICATOR_REMOTE_PROTOCOL'; | ||||
| const EMPTY_HASH = '0000000000000000000000000000000000000000'; | const EMPTY_HASH = '0000000000000000000000000000000000000000'; | ||||
| private $viewer; | private $viewer; | ||||
| private $repository; | private $repository; | ||||
| private $stdin; | private $stdin; | ||||
| private $originalArgv; | private $originalArgv; | ||||
| private $subversionTransaction; | private $subversionTransaction; | ||||
| private $subversionRepository; | private $subversionRepository; | ||||
| private $remoteAddress; | private $remoteAddress; | ||||
| private $remoteProtocol; | private $remoteProtocol; | ||||
| private $requestIdentifier; | |||||
| private $transactionKey; | private $transactionKey; | ||||
| private $mercurialHook; | private $mercurialHook; | ||||
| private $mercurialCommits = array(); | private $mercurialCommits = array(); | ||||
| private $gitCommits = array(); | private $gitCommits = array(); | ||||
| private $heraldViewerProjects; | private $heraldViewerProjects; | ||||
| private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; | private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; | ||||
| private $rejectDetails; | private $rejectDetails; | ||||
| Show All 17 Lines | public function setRemoteAddress($remote_address) { | ||||
| $this->remoteAddress = $remote_address; | $this->remoteAddress = $remote_address; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getRemoteAddress() { | public function getRemoteAddress() { | ||||
| return $this->remoteAddress; | return $this->remoteAddress; | ||||
| } | } | ||||
| public function setRequestIdentifier($request_identifier) { | |||||
| $this->requestIdentifier = $request_identifier; | |||||
| return $this; | |||||
| } | |||||
| public function getRequestIdentifier() { | |||||
| return $this->requestIdentifier; | |||||
| } | |||||
| public function setSubversionTransactionInfo($transaction, $repository) { | public function setSubversionTransactionInfo($transaction, $repository) { | ||||
| $this->subversionTransaction = $transaction; | $this->subversionTransaction = $transaction; | ||||
| $this->subversionRepository = $repository; | $this->subversionRepository = $repository; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setStdin($stdin) { | public function setStdin($stdin) { | ||||
| $this->stdin = $stdin; | $this->stdin = $stdin; | ||||
| ▲ Show 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | /* -( Custom )------------------------------------------------------------- */ | ||||
| private function applyCustomHooks(array $updates) { | private function applyCustomHooks(array $updates) { | ||||
| $args = $this->getOriginalArgv(); | $args = $this->getOriginalArgv(); | ||||
| $stdin = $this->getStdin(); | $stdin = $this->getStdin(); | ||||
| $console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
| $env = array( | $env = array( | ||||
| self::ENV_REPOSITORY => $this->getRepository()->getPHID(), | self::ENV_REPOSITORY => $this->getRepository()->getPHID(), | ||||
| self::ENV_USER => $this->getViewer()->getUsername(), | self::ENV_USER => $this->getViewer()->getUsername(), | ||||
| self::ENV_REQUEST => $this->getRequestIdentifier(), | |||||
| self::ENV_REMOTE_PROTOCOL => $this->getRemoteProtocol(), | self::ENV_REMOTE_PROTOCOL => $this->getRemoteProtocol(), | ||||
| self::ENV_REMOTE_ADDRESS => $this->getRemoteAddress(), | self::ENV_REMOTE_ADDRESS => $this->getRemoteAddress(), | ||||
| ); | ); | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $env += $repository->getPassthroughEnvironmentalVariables(); | $env += $repository->getPassthroughEnvironmentalVariables(); | ||||
| ▲ Show 20 Lines • Show All 445 Lines • ▼ Show 20 Lines | if ($device) { | ||||
| $device_phid = null; | $device_phid = null; | ||||
| } | } | ||||
| return PhabricatorRepositoryPushLog::initializeNewLog($this->getViewer()) | return PhabricatorRepositoryPushLog::initializeNewLog($this->getViewer()) | ||||
| ->setPHID($phid) | ->setPHID($phid) | ||||
| ->setDevicePHID($device_phid) | ->setDevicePHID($device_phid) | ||||
| ->setRepositoryPHID($this->getRepository()->getPHID()) | ->setRepositoryPHID($this->getRepository()->getPHID()) | ||||
| ->attachRepository($this->getRepository()) | ->attachRepository($this->getRepository()) | ||||
| ->setEpoch(time()); | ->setEpoch(PhabricatorTime::getNow()); | ||||
| } | } | ||||
| private function newPushEvent() { | private function newPushEvent() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| return PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) | |||||
| $event = PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) | |||||
| ->setRepositoryPHID($this->getRepository()->getPHID()) | ->setRepositoryPHID($this->getRepository()->getPHID()) | ||||
| ->setRemoteAddress($this->getRemoteAddress()) | ->setRemoteAddress($this->getRemoteAddress()) | ||||
| ->setRemoteProtocol($this->getRemoteProtocol()) | ->setRemoteProtocol($this->getRemoteProtocol()) | ||||
| ->setEpoch(time()); | ->setEpoch(PhabricatorTime::getNow()); | ||||
| $identifier = $this->getRequestIdentifier(); | |||||
| if (strlen($identifier)) { | |||||
| $event->setRequestIdentifier($identifier); | |||||
| } | |||||
| return $event; | |||||
| } | } | ||||
| private function rejectEnormousChanges(array $content_updates) { | private function rejectEnormousChanges(array $content_updates) { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| if ($repository->shouldAllowEnormousChanges()) { | if ($repository->shouldAllowEnormousChanges()) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines | |||||