示例#1
0
 /**
  * Fetch root identifier from GitHub
  *
  * @throws TransportException
  */
 protected function fetchRootIdentifier()
 {
     $repoDataUrl = 'https://api.github.com/repos/' . $this->owner . '/' . $this->repository;
     $attemptCounter = 0;
     while (null === $this->rootIdentifier) {
         if (5 == $attemptCounter++) {
             throw new \RuntimeException("Either you have entered invalid credentials or this GitHub repository does not exists (404)");
         }
         try {
             $repoData = JsonFile::parseJson($this->getContents($repoDataUrl), $repoDataUrl);
             if (isset($repoData['default_branch'])) {
                 $this->rootIdentifier = $repoData['default_branch'];
             } elseif (isset($repoData['master_branch'])) {
                 $this->rootIdentifier = $repoData['master_branch'];
             } else {
                 $this->rootIdentifier = 'master';
             }
             $this->hasIssues = !empty($repoData['has_issues']);
         } catch (TransportException $e) {
             switch ($e->getCode()) {
                 case 401:
                 case 404:
                     $this->isPrivate = true;
                     try {
                         // If this repository may be private (hard to say for sure,
                         // GitHub returns 404 for private repositories) and we
                         // cannot ask for authentication credentials (because we
                         // are not interactive) then we fallback to GitDriver.
                         $this->gitDriver = new GitDriver($this->generateSshUrl(), $this->io, $this->config, $this->process, $this->remoteFilesystem);
                         $this->gitDriver->initialize();
                         return;
                     } catch (\RuntimeException $e) {
                         $this->gitDriver = null;
                         if (!$this->io->isInteractive()) {
                             $this->io->write('<error>Failed to clone the ' . $this->generateSshUrl() . ' repository, try running in interactive mode so that you can enter your username and password</error>');
                             throw $e;
                         }
                     }
                     $this->io->write('Authentication required (<info>' . $this->url . '</info>):');
                     $username = $this->io->ask('Username: '******'Password: ');
                     $this->io->setAuthorization($this->originUrl, $username, $password);
                     break;
                 default:
                     throw $e;
                     break;
             }
         }
     }
 }
 protected function attemptCloneFallback()
 {
     $this->isPrivate = true;
     try {
         // If this repository may be private (hard to say for sure,
         // GitHub returns 404 for private repositories) and we
         // cannot ask for authentication credentials (because we
         // are not interactive) then we fallback to GitDriver.
         $this->gitDriver = new GitDriver(array('url' => $this->generateSshUrl()), $this->io, $this->config, $this->process, $this->remoteFilesystem);
         $this->gitDriver->initialize();
         return;
     } catch (\RuntimeException $e) {
         $this->gitDriver = null;
         $this->io->write('<error>Failed to clone the ' . $this->generateSshUrl() . ' repository, try running in interactive mode so that you can enter your GitHub credentials</error>');
         throw $e;
     }
 }
示例#3
0
 protected function setupGitDriver($url)
 {
     $this->gitDriver = new GitDriver(array('url' => $url), $this->io, $this->config, $this->process, $this->remoteFilesystem);
     $this->gitDriver->initialize();
 }
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     $this->drupalProjectName = $this->repoConfig['drupalProjectName'];
     $this->isCore = $this->drupalProjectName === 'drupal';
     parent::initialize();
 }