Exemplo n.º 1
0
 public function getComposerInformation($identifier)
 {
     $this->buildNameMapping();
     $composerInformation = parent::getComposerInformation($identifier);
     if (!$composerInformation) {
         $resource = sprintf('%s:ext_emconf.php', escapeshellarg($identifier));
         $this->process->execute(sprintf('git show %s', $resource), $emConf, $this->repoDir);
         if (!trim($emConf)) {
             // No emconf at all, we skip
             return;
         }
         $emConfConverter = new EmConfReader();
         $extensionConfig = $emConfConverter->readFromString($emConf);
         if (empty($extensionConfig) || !preg_match('/^[\\d]+\\.[\\d]+(\\.[\\d])*$/', str_replace('-dev', '', $extensionConfig['version']))) {
             // Could not read extension config or invalid version number, we skip
             return;
         }
         $composerInformation = $this->getComposerInformationFromEmConf($extensionConfig, $identifier);
         if (false === json_encode($composerInformation, 448)) {
             // Most likely wrong encoding (not UTF-8) which we cannot fix here
             return;
         }
         if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
             $this->cache->write($identifier, json_encode($composerInformation));
         }
         $this->infoCache[$identifier] = $composerInformation;
     }
     return $composerInformation;
 }
Exemplo n.º 2
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;
             }
         }
     }
 }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
 protected function setupGitDriver($url)
 {
     $this->gitDriver = new GitDriver(array('url' => $url), $this->io, $this->config, $this->process, $this->remoteFilesystem);
     $this->gitDriver->initialize();
 }
Exemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function initialize()
 {
     $this->drupalProjectName = $this->repoConfig['drupalProjectName'];
     $this->isCore = $this->drupalProjectName === 'drupal';
     parent::initialize();
 }