1
0
Fork 0

Retry fetching composer.json files twice since github returns 404s at random at the moment

@bhuga confirmed it is the best approach until github finds a fix. /cc @gillesruppert enjoy whatever your bet wins you
pull/1903/merge
Jordi Boggiano 2013-05-16 02:26:06 +02:00
parent 3f2b9b4d4b
commit 5267bafa2c
1 changed files with 18 additions and 11 deletions

View File

@ -127,19 +127,26 @@ class GitHubDriver extends VcsDriver
} }
if (!isset($this->infoCache[$identifier])) { if (!isset($this->infoCache[$identifier])) {
$notFoundRetries = 2;
while ($notFoundRetries) {
try { try {
$resource = 'https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/contents/composer.json?ref='.urlencode($identifier); $resource = 'https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/contents/composer.json?ref='.urlencode($identifier);
$composer = JsonFile::parseJson($this->getContents($resource)); $composer = JsonFile::parseJson($this->getContents($resource));
if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) { if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) {
throw new \RuntimeException('Could not retrieve composer.json from '.$resource); throw new \RuntimeException('Could not retrieve composer.json from '.$resource);
} }
break;
} catch (TransportException $e) { } catch (TransportException $e) {
if (404 !== $e->getCode()) { if (404 !== $e->getCode()) {
throw $e; throw $e;
} }
// TODO should be removed when possible
// retry fetching if github returns a 404 since they happen randomly
$notFoundRetries--;
$composer = false; $composer = false;
} }
}
if ($composer) { if ($composer) {
$composer = JsonFile::parseJson($composer, $resource); $composer = JsonFile::parseJson($composer, $resource);