From: Michael Wallner Date: Fri, 16 Dec 2016 09:15:21 +0000 (+0100) Subject: github: honor redirect in readrepo X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=eb28087be80d91f0fd2cf8ce552eacedcd82a638;p=pharext%2Fpharext.org github: honor redirect in readrepo --- diff --git a/app/Github/API/Repos/ReadRepo.php b/app/Github/API/Repos/ReadRepo.php index 15c0314..00b9d2c 100644 --- a/app/Github/API/Repos/ReadRepo.php +++ b/app/Github/API/Repos/ReadRepo.php @@ -11,17 +11,35 @@ class ReadRepo extends Call { function request() { $url = $this->url->mod(uri_template("./repos/{+repo}", $this->args)); + return $this->requestUrl($url); + } + + function requestUrl($url) { $request = new Request("GET", $url, [ "Authorization" => "token " . $this->api->getToken(), "Accept" => $this->config->api->accept, ]); return $request; } - + function response(Response $response) { if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) { throw new RequestException($response); } + if ($response->getResponseCode() >= 300 && $response->getResponseCode() < 400) { + $this->api->getClient()->enqueue( + $this->requestUrl($json->url), + function($response) { + try { + $this->deferred->resolve($this->response($response)); + } catch (\Exception $e) { + $this->deferred->reject($e); + } + return true; + } + ); + return $this->deferred->promise(); + } $result = [$json]; $this->saveToCache($result); return $result;