Ejemplo n.º 1
0
 /**
  * Get the remote content.
  *
  * @param string $url              The URL of content
  * @param bool   $fetchingRepoData Fetching the repo data or not
  *
  * @return mixed The result
  */
 protected function getContents($url, $fetchingRepoData = false)
 {
     $url = $this->getValidContentUrl($url);
     if (null !== $this->redirectApi) {
         return parent::getContents($url, $fetchingRepoData);
     }
     try {
         $contents = $this->getRemoteContents($url);
         $this->redirectApi = false;
         return $contents;
     } catch (TransportException $e) {
         if ($this->hasRedirectUrl($url)) {
             $url = $this->getValidContentUrl($url);
         }
         return parent::getContents($url, $fetchingRepoData);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string|null $identifier
  *
  * @return array|bool
  */
 public function getComposerInformation($identifier = null)
 {
     $composerInfo = $this->driver->getComposerInformation($identifier ? $identifier : $this->driver->getRootIdentifier());
     if (!$composerInfo) {
         $this->log->write('github driver: no composer.json found for ' . ($identifier ? $identifier : 'master'));
         $composerInfo = $this->convertPackageXml($identifier);
         if (!$composerInfo) {
             $this->log->write('github driver: no package2.xml or package.xml found for ' . ($identifier ? $identifier : 'master'));
             return false;
         }
     }
     if ($composerInfo['name'] != $this->name) {
         $this->log->write($identifier . " composer.json name does not match master's one, skipping");
         return false;
     }
     $composerInfo['source'] = $this->driver->getSource($identifier);
     $composerInfo['dist'] = $this->driver->getDist($identifier);
     return $composerInfo;
 }
Ejemplo n.º 3
0
 public function testPrivateRepositoryNoInteraction()
 {
     $scheme = extension_loaded('openssl') ? 'https' : 'http';
     $repoUrl = 'http://github.com/composer/packagist';
     $repoApiUrl = $scheme . '://api.github.com/repos/composer/packagist';
     $repoSshUrl = 'git@github.com:composer/packagist.git';
     $identifier = 'v0.0.0';
     $sha = 'SOMESHA';
     $process = $this->getMockBuilder('Composer\\Util\\ProcessExecutor')->disableOriginalConstructor()->getMock();
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $io->expects($this->any())->method('isInteractive')->will($this->returnValue(false));
     $remoteFilesystem = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->setConstructorArgs(array($io))->getMock();
     $remoteFilesystem->expects($this->at(0))->method('getContents')->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     // clean local clone if present
     $fs = new Filesystem();
     $fs->removeDirectory(sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9.]}i', '-', $repoSshUrl) . '/');
     $process->expects($this->at(0))->method('execute')->with($this->stringContains($repoSshUrl))->will($this->returnValue(0));
     $process->expects($this->at(1))->method('execute')->with($this->stringContains('git tag'));
     $process->expects($this->at(2))->method('splitLines')->will($this->returnValue(array($identifier)));
     $process->expects($this->at(3))->method('execute')->with($this->stringContains('git branch --no-color --no-abbrev -v'));
     $process->expects($this->at(4))->method('splitLines')->will($this->returnValue(array('  test_master     edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior')));
     $process->expects($this->at(5))->method('execute')->with($this->stringContains('git branch --no-color'));
     $process->expects($this->at(6))->method('splitLines')->will($this->returnValue(array('* test_master')));
     $gitHubDriver = new GitHubDriver($repoUrl, $io, $process, $remoteFilesystem);
     $gitHubDriver->initialize();
     $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
     // Dist is not available for GitDriver
     $dist = $gitHubDriver->getDist($identifier);
     $this->assertNull($dist);
     $source = $gitHubDriver->getSource($identifier);
     $this->assertEquals('git', $source['type']);
     $this->assertEquals($repoSshUrl, $source['url']);
     $this->assertEquals($identifier, $source['reference']);
     // Dist is not available for GitDriver
     $dist = $gitHubDriver->getDist($sha);
     $this->assertNull($dist);
     $source = $gitHubDriver->getSource($sha);
     $this->assertEquals('git', $source['type']);
     $this->assertEquals($repoSshUrl, $source['url']);
     $this->assertEquals($sha, $source['reference']);
 }
Ejemplo n.º 4
0
 public function testPrivateRepositoryNoInteraction()
 {
     $repoUrl = 'http://github.com/composer/packagist';
     $repoApiUrl = 'https://api.github.com/repos/composer/packagist';
     $repoSshUrl = 'git@github.com:composer/packagist.git';
     $identifier = 'v0.0.0';
     $sha = 'SOMESHA';
     $process = $this->getMockBuilder('Composer\\Util\\ProcessExecutor')->disableOriginalConstructor()->getMock();
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $io->expects($this->any())->method('isInteractive')->will($this->returnValue(false));
     $remoteFilesystem = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->setConstructorArgs(array($io))->getMock();
     $remoteFilesystem->expects($this->at(0))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     // clean local clone if present
     $fs = new Filesystem();
     $fs->removeDirectory(sys_get_temp_dir() . '/composer-test');
     $process->expects($this->at(0))->method('execute')->with($this->equalTo('git config github.accesstoken'))->will($this->returnValue(1));
     $process->expects($this->at(1))->method('execute')->with($this->stringContains($repoSshUrl))->will($this->returnValue(0));
     $process->expects($this->at(2))->method('execute')->with($this->stringContains('git show-ref --tags'));
     $process->expects($this->at(3))->method('splitLines')->will($this->returnValue(array($sha . ' refs/tags/' . $identifier)));
     $process->expects($this->at(4))->method('execute')->with($this->stringContains('git branch --no-color --no-abbrev -v'));
     $process->expects($this->at(5))->method('splitLines')->will($this->returnValue(array('  test_master     edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior')));
     $process->expects($this->at(6))->method('execute')->with($this->stringContains('git branch --no-color'));
     $process->expects($this->at(7))->method('splitLines')->will($this->returnValue(array('* test_master')));
     $repoConfig = array('url' => $repoUrl);
     $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
     $gitHubDriver->initialize();
     $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
     $dist = $gitHubDriver->getDist($sha);
     $this->assertEquals('zip', $dist['type']);
     $this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']);
     $this->assertEquals($sha, $dist['reference']);
     $source = $gitHubDriver->getSource($identifier);
     $this->assertEquals('git', $source['type']);
     $this->assertEquals($repoSshUrl, $source['url']);
     $this->assertEquals($identifier, $source['reference']);
     $source = $gitHubDriver->getSource($sha);
     $this->assertEquals('git', $source['type']);
     $this->assertEquals($repoSshUrl, $source['url']);
     $this->assertEquals($sha, $source['reference']);
 }