From 5267bafa2cb28e564dbca8d1bfaa64de2a120827 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 16 May 2013 02:26:06 +0200 Subject: [PATCH] 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 --- src/Composer/Repository/Vcs/GitHubDriver.php | 29 ++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index f7cb948a8..b9f28f59a 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -127,18 +127,25 @@ class GitHubDriver extends VcsDriver } if (!isset($this->infoCache[$identifier])) { - try { - $resource = 'https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/contents/composer.json?ref='.urlencode($identifier); - $composer = JsonFile::parseJson($this->getContents($resource)); - if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) { - throw new \RuntimeException('Could not retrieve composer.json from '.$resource); - } - } catch (TransportException $e) { - if (404 !== $e->getCode()) { - throw $e; - } + $notFoundRetries = 2; + while ($notFoundRetries) { + try { + $resource = 'https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/contents/composer.json?ref='.urlencode($identifier); + $composer = JsonFile::parseJson($this->getContents($resource)); + if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) { + throw new \RuntimeException('Could not retrieve composer.json from '.$resource); + } + break; + } catch (TransportException $e) { + if (404 !== $e->getCode()) { + throw $e; + } - $composer = false; + // TODO should be removed when possible + // retry fetching if github returns a 404 since they happen randomly + $notFoundRetries--; + $composer = false; + } } if ($composer) {