From 4dc995a157fd4d9543a03ad09a6b2a3e9ccd0066 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Fri, 25 Aug 2017 10:28:49 +0200 Subject: [PATCH] Use Gitlab API V4 --- composer.json | 3 ++- confs/samples/gitlab.ini | 2 +- htdocs/packages.php | 13 ++++--------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 33d0db5..d1516fb 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "require": { - "m4tthumphrey/php-gitlab-api": "dev-master" + "m4tthumphrey/php-gitlab-api": "^9.0", + "php-http/guzzle6-adapter": "^1.1" } } diff --git a/confs/samples/gitlab.ini b/confs/samples/gitlab.ini index 43551b9..99e0854 100644 --- a/confs/samples/gitlab.ini +++ b/confs/samples/gitlab.ini @@ -2,7 +2,7 @@ ; Copy this file in parent directory ; api_key can be found at http://gitlab.example.com/profile/account ; method It is the method for the URL of the project (ssh/http) -endpoint="http://gitlab.example.com/api/v3/" +endpoint="http://gitlab.example.com/api/v4/" api_key="ASDFGHJKL12345678" method="ssh" ; You can restrict to some gitlab groups: diff --git a/htdocs/packages.php b/htdocs/packages.php index dc02366..39a4226 100644 --- a/htdocs/packages.php +++ b/htdocs/packages.php @@ -34,7 +34,7 @@ } $confs = parse_ini_file($config_file); -$client = new Client($confs['endpoint']); +$client = Client::create($confs['endpoint']); $client->authenticate($confs['api_key'], Client::AUTH_URL_TOKEN); $groups = $client->api('groups'); @@ -164,11 +164,11 @@ $mtime = 0; if (!empty($confs['groups'])) { // We have to get projects from specifics groups - foreach ($groups->all(1, 100) as $group) { + foreach ($groups->all(array('page' => 1, 'per_page' => 100)) as $group) { if (!in_array($group['name'], $confs['groups'], true)) { continue; } - for ($page = 1; count($p = $groups->projects($group['id'], $page, 100)); $page++) { + for ($page = 1; count($p = $groups->projects($group['id'], array('page' => $page, 'per_page' => 100))); $page++) { foreach ($p as $project) { $all_projects[] = $project; $mtime = max($mtime, strtotime($project['last_activity_at'])); @@ -178,12 +178,7 @@ } else { // We have to get all accessible projects $me = $client->api('users')->me(); - if ((bool)$me['is_admin']) { - $projects_api_method = 'all'; - } else { - $projects_api_method = 'accessible'; - } - for ($page = 1; count($p = $projects->$projects_api_method($page, 100)); $page++) { + for ($page = 1; count($p = $projects->all(array('page' => $page, 'per_page' => 100))); $page++) { foreach ($p as $project) { $all_projects[] = $project; $mtime = max($mtime, strtotime($project['last_activity_at']));