From a144b5e7edaa2f0b5e44cd3a76dae5ed1cb6e351 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 18 Aug 2017 14:04:53 +0200 Subject: [PATCH] Fix GitLab endless loop thanks to API bug, fixes #6615 --- src/Composer/Repository/Vcs/GitLabDriver.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index dd481d7ec..f2813db54 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -278,7 +278,8 @@ class GitLabDriver extends VcsDriver */ protected function getReferences($type) { - $resource = $this->getApiUrl().'/repository/'.$type.'?per_page=100'; + $perPage = 100; + $resource = $this->getApiUrl().'/repository/'.$type.'?per_page='.$perPage; $references = array(); do { @@ -287,11 +288,16 @@ class GitLabDriver extends VcsDriver foreach ($data as $datum) { $references[$datum['name']] = $datum['commit']['id']; - // Keep the last commit date of a reference to avoid - // unnecessary API call when retrieving the composer file. - $this->commits[$datum['commit']['id']] = $datum['commit']; + // Keep the last commit date of a reference to avoid + // unnecessary API call when retrieving the composer file. + $this->commits[$datum['commit']['id']] = $datum['commit']; + } + + if (count($data) >= $perPage) { + $resource = $this->getNextPage(); + } else { + $resource = false; } - $resource = $this->getNextPage(); } while ($resource); return $references;