public function install(DriverConfig $config) { if (is_dir($config->getDirectory())) { $command = sprintf('cd "%s" && git pull origin %s', $config->getDirectory(), $config->getBranch()); } else { $command = sprintf('git clone -b %s %s "%s"', $config->getBranch(), $config->getRepository(), $config->getDirectory()); } $process = new Process($command); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } return $process->getOutput(); }
/** * Listens for incoming requests. * * @throws InvalidRequestException */ public function listen() { if ($_SERVER['REQUEST_METHOD'] != 'POST') { throw new InvalidRequestException('Expected a POST request.'); } $remoteAddress = $this->getRemoteAddress(); if (!$this->isValidRemoteAddress($remoteAddress)) { throw new InvalidRequestException('Invalid remote address.'); } if (empty($_POST[$this->parameter])) { throw new InvalidRequestException('Expected the parameter ' . $this->parameter); } $payload = new Payload($_POST['payload']); $configuration = $this->getConfiguration($payload->getRepository()); if (!$configuration) { throw new InvalidRequestException('Invalid repository: ' . $payload->getRepository()); } if ($configuration->getDriver() != 'git') { throw new InvalidRequestException('Project is not a git repository but ' . $configuration->getDriver()); } $driverConfig = new DriverConfig(); $driverConfig->setDirectory($configuration->getSource()); $driverConfig->setBranch($payload->getBranch()); $driverConfig->setRepository($configuration->getRepository()); $driver = new GitDriver(); $driver->install($driverConfig); $generator = $this->configureGenerator($configuration, $payload); $generator->generate(); }