Skip to content

Commit

Permalink
Use Gitlab API V4
Browse files Browse the repository at this point in the history
  • Loading branch information
blankse authored and lemoinem committed Aug 28, 2017
1 parent 72e971c commit 4dc995a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"require": {
"m4tthumphrey/php-gitlab-api": "dev-master"
"m4tthumphrey/php-gitlab-api": "^9.0",
"php-http/guzzle6-adapter": "^1.1"
}
}
2 changes: 1 addition & 1 deletion confs/samples/gitlab.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 4 additions & 9 deletions htdocs/packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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']));
Expand All @@ -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']));
Expand Down

0 comments on commit 4dc995a

Please sign in to comment.