Skip to content

Commit

Permalink
Allows restricting Gitlab groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Guyomard authored and lemoinem committed Jul 6, 2017
1 parent bc1135e commit 72e971c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
5 changes: 4 additions & 1 deletion confs/samples/gitlab.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
; method It is the method for the URL of the project (ssh/http)
endpoint="http://gitlab.example.com/api/v3/"
api_key="ASDFGHJKL12345678"
method="ssh"
method="ssh"
; You can restrict to some gitlab groups:
;groups[]="one_group"
;groups[]="other_group"
39 changes: 28 additions & 11 deletions htdocs/packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
$client = new Client($confs['endpoint']);
$client->authenticate($confs['api_key'], Client::AUTH_URL_TOKEN);

$groups = $client->api('groups');
$projects = $client->api('projects');
$repos = $client->api('repositories');

Expand Down Expand Up @@ -158,23 +159,39 @@
}
};

// Load projects
$all_projects = array();
$mtime = 0;

$me = $client->api('users')->me();
if ((bool)$me['is_admin']) {
$projects_api_method = 'all';
if (!empty($confs['groups'])) {
// We have to get projects from specifics groups
foreach ($groups->all(1, 100) as $group) {
if (!in_array($group['name'], $confs['groups'], true)) {
continue;
}
for ($page = 1; count($p = $groups->projects($group['id'], $page, 100)); $page++) {
foreach ($p as $project) {
$all_projects[] = $project;
$mtime = max($mtime, strtotime($project['last_activity_at']));
}
}
}
} else {
$projects_api_method = 'accessible';
}

for ($page = 1; count($p = $projects->$projects_api_method($page, 100)); $page++) {
foreach ($p as $project) {
$all_projects[] = $project;
$mtime = max($mtime, strtotime($project['last_activity_at']));
// 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++) {
foreach ($p as $project) {
$all_projects[] = $project;
$mtime = max($mtime, strtotime($project['last_activity_at']));
}
}
}

// Regenerate packages_file is needed
if (!file_exists($packages_file) || filemtime($packages_file) < $mtime) {
$packages = array();
foreach ($all_projects as $project) {
Expand Down

0 comments on commit 72e971c

Please sign in to comment.