diff --git a/confs/samples/gitlab.ini b/confs/samples/gitlab.ini index e164b8b..43551b9 100644 --- a/confs/samples/gitlab.ini +++ b/confs/samples/gitlab.ini @@ -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" \ No newline at end of file +method="ssh" +; You can restrict to some gitlab groups: +;groups[]="one_group" +;groups[]="other_group" diff --git a/htdocs/packages.php b/htdocs/packages.php index 7471a6a..dc02366 100644 --- a/htdocs/packages.php +++ b/htdocs/packages.php @@ -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'); @@ -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) {