Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
| <?php | <?php | ||||
| final class DiffusionCommitHookEngine extends Phobject { | final class DiffusionCommitHookEngine extends Phobject { | ||||
| private $viewer; | private $viewer; | ||||
| private $repository; | private $repository; | ||||
| private $stdin; | private $stdin; | ||||
| private $subversionTransaction; | |||||
| private $subversionRepository; | |||||
| public function setSubversionTransactionInfo($transaction, $repository) { | |||||
| $this->subversionTransaction = $transaction; | |||||
| $this->subversionRepository = $repository; | |||||
| return $this; | |||||
| } | |||||
| public function setStdin($stdin) { | public function setStdin($stdin) { | ||||
| $this->stdin = $stdin; | $this->stdin = $stdin; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getStdin() { | public function getStdin() { | ||||
| return $this->stdin; | return $this->stdin; | ||||
| Show All 18 Lines | final class DiffusionCommitHookEngine extends Phobject { | ||||
| } | } | ||||
| public function execute() { | public function execute() { | ||||
| $type = $this->getRepository()->getVersionControlSystem(); | $type = $this->getRepository()->getVersionControlSystem(); | ||||
| switch ($type) { | switch ($type) { | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: | case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: | ||||
| $err = $this->executeGitHook(); | $err = $this->executeGitHook(); | ||||
| break; | break; | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | |||||
| $err = $this->executeSubversionHook(); | |||||
| break; | |||||
| default: | default: | ||||
| throw new Exception(pht('Unsupported repository type "%s"!', $type)); | throw new Exception(pht('Unsupported repository type "%s"!', $type)); | ||||
| } | } | ||||
| return $err; | return $err; | ||||
| } | } | ||||
| private function executeGitHook() { | private function executeGitHook() { | ||||
| $updates = $this->parseGitUpdates($this->getStdin()); | $updates = $this->parseGitUpdates($this->getStdin()); | ||||
| // TODO: Do useful things. | // TODO: Do useful things. | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| private function executeSubversionHook() { | |||||
| // TODO: Do useful things here, too. | |||||
| return 0; | |||||
| } | |||||
| private function parseGitUpdates($stdin) { | private function parseGitUpdates($stdin) { | ||||
| $updates = array(); | $updates = array(); | ||||
| $lines = phutil_split_lines($stdin, $retain_endings = false); | $lines = phutil_split_lines($stdin, $retain_endings = false); | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| $parts = explode(' ', $line, 3); | $parts = explode(' ', $line, 3); | ||||
| if (count($parts) != 3) { | if (count($parts) != 3) { | ||||
| throw new Exception(pht('Expected "old new ref", got "%s".', $line)); | throw new Exception(pht('Expected "old new ref", got "%s".', $line)); | ||||
| Show All 12 Lines | |||||