From 01d062a435e8e8a6590ce7867dba9056e92d2b2b Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 30 Apr 2024 13:35:58 +0800 Subject: [PATCH] + Add the method to get MRs by API. --- module/gitlab/model.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 9f3abe8f17..ee8c951d99 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -490,6 +490,31 @@ class gitlabModel extends model return $allResults; } + /** + * API获取项目的合并请求列表。 + * Get Merge Requests by API. + * + * @param int $gitlabID + * @param int $projectID + * @return array + */ + public function apiGetMergeRequests(int $gitlabID, int $projectID): array + { + $apiRoot = $this->getApiRoot((int)$gitlabID); + $url = sprintf($apiRoot, "/projects/$projectID/merge_requests"); + + $MRs = array(); + for($page = 1; true; $page++) + { + $onePageMRs = json_decode(commonModel::http($url . "&&page={$page}&per_page=100")); + if(!is_array($onePageMRs)) break; + if(!empty($onePageMRs)) $MRs = array_merge($MRs, $onePageMRs); + if(count($onePageMRs) < 100) break; + } + + return $MRs; + } + /** * 获取gitlab命名空间列表。 * Get namespaces of one gitlab.