From f69222b56e5a5a2b47605761a3fdff65746b02bb Mon Sep 17 00:00:00 2001 From: zenggang Date: Fri, 8 Apr 2022 06:24:00 +0000 Subject: [PATCH] * Fix bug#20630 --- lib/scm/gitlab.class.php | 14 +++++++++----- module/gitlab/model.php | 7 +++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index 1d702b267b..a94bfdc9e8 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -66,7 +66,7 @@ class gitlab } else { - $commits = $this->getCommitsByPath($file->path); + $commits = $this->getCommitsByPath($file->path, '', '', 1); if(empty($commits)) continue; $commit = $commits[0]; @@ -108,7 +108,7 @@ class gitlab $file = $this->fetch($api, $param); if(!isset($file->file_name)) return false; - $commits = $this->getCommitsByPath($path); + $commits = $this->getCommitsByPath($path, '', '', 1); $file->revision = $file->commit_id; $file->size = $this->formatBytes($file->size); @@ -636,10 +636,13 @@ class gitlab * Get commits by path. * * @param string $path + * @param string $fromRevision + * @param string $toRevision + * @param int $perPage * @access public * @return array */ - public function getCommitsByPath($path, $fromRevision = '', $toRevision = '') + public function getCommitsByPath($path, $fromRevision = '', $toRevision = '', $perPage = 0) { $path = ltrim($path, DIRECTORY_SEPARATOR); $api = "commits"; @@ -662,10 +665,11 @@ class gitlab { $since = $fromDate; } - if($since) $param->since = $since; if($until) $param->until = $until; + if($perPage) $param->per_page = $perPage; + return $this->fetch($api, $param); } @@ -742,7 +746,7 @@ class gitlab { $params = (array) $params; $params['private_token'] = $this->token; - $params['per_page'] = 100; + $params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100; $api = ltrim($api, '/'); $api = $this->root . $api . '?' . http_build_query($params); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index ae76ba33bb..54ed60e29a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -492,6 +492,7 @@ class gitlabModel extends model { /* GitLab API '/users' can only return 20 users per page in default, so we use a loop to fetch all users. */ $page = 1; + $perPage = 100; $response = array(); $apiRoot = $this->getApiRoot($gitlabID); @@ -503,12 +504,14 @@ class gitlabModel extends model while(true) { /* Also use `per_page=20` to fetch users in API. Fetch active users only. */ - $url = sprintf($apiRoot, "/users") . "&order_by={$order}&sort={$sort}&page={$page}&per_page=20&active=true"; - $result = json_decode(commonModel::http($url)); + $url = sprintf($apiRoot, "/users") . "&order_by={$order}&sort={$sort}&page={$page}&per_page={$perPage}&active=true"; + $httpData = commonModel::httpWithHeader($url); + $result = json_decode($httpData['body']); if(!empty($result)) { $response = array_merge($response, $result); $page += 1; + if($httpData['header']['X-Page'] == $httpData['header']['X-Total-Pages']) break; } else {