Example #1
0
 /**
  * @param RemoteInterface $remote
  * @param string $destination
  * @param array $options
  */
 public function cloneRemote(RemoteInterface $remote, $destination, array $options = null)
 {
     $options = array_merge($this->defaultOptions, $options ?: []);
     $this->getEmitter()->emit(GitRemoteEvent::prepare('git_guardian.pre_clone_remote', $remote, ['destination' => $destination, 'options' => $options ?: []]));
     $repositories = $remote->getRepositories();
     $fs = new Filesystem();
     if (!$fs->exists($destination)) {
         $fs->mkdir($destination, 0770);
     }
     foreach ($repositories as $repository) {
         try {
             $this->cloneRepository($repository, $destination, $options);
         } catch (GitProcessException $e) {
             $this->getEmitter()->emit(GitRepositoryEvent::prepare('git_guardian.exception_repository', $repository, 'error', null, ['destination' => $destination, 'options' => $options ?: [], 'exception' => $e]));
         }
     }
     $this->getEmitter()->emit(GitRemoteEvent::prepare('git_guardian.post_clone_remote', $remote, ['destination' => $destination, 'options' => $options ?: []]));
 }
 /**
  * @param string $method
  * @param string $endpoint
  * @param array|null $options
  * @param bool $requireAuth
  * @return Response
  */
 public function sendClientRequest($method, $endpoint, array $options = null, $requireAuth = false)
 {
     if ($requireAuth) {
         $token = $this->getToken();
         if ($token) {
             $options = array_merge_recursive($options ?: [], ['headers' => ['Authorization' => sprintf('%s %s', ucfirst(strtolower($token['token_type'])), $token['access_token'])]]);
         }
     }
     $this->getEmitter()->emit(GitRemoteEvent::prepare('git_remote.client_request', $this, ['endpoint' => $endpoint]));
     /** @var Response $response */
     $response = $this->client->{$method}($endpoint, $options ?: []);
     if (200 !== $response->getStatusCode()) {
         throw new AdapterException(sprintf('Response is not OK for "%s"', $endpoint));
     }
     return $response;
 }