Skip to content

Instantly share code, notes, and snippets.

@bobey
Last active January 12, 2016 15:05
Show Gist options
  • Save bobey/2b09d2cc72fbcc8cf551 to your computer and use it in GitHub Desktop.
Save bobey/2b09d2cc72fbcc8cf551 to your computer and use it in GitHub Desktop.
Git clone ALL the Gitlab Projets of given namespace in one command
curl -sS https://gist.githubusercontent.com/bobey/2b09d2cc72fbcc8cf551/raw/get-gitlab-projets.php | \
php -- http://gitlab.com YOUR-PRIVATE-TOKEN your-namespace | \
xargs -n 1 git clone
<?php
// $gitlabUrl
if (count($argv) !== 4) {
echo 'Bad arguments number supplied. Usage `php get-gitlab-projets.php [http://gitlab.com] [YOUR-PRIVATE-TOKEN] [namespace]`';
exit(1);
}
$gitlabUrl = $argv[1];
$privateToken = $argv[2];
$namespace = $argv[3];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => sprintf('%s/api/v3/projects?per_page=100&private_token=%s', $gitlabUrl, $privateToken),
]);
$response = curl_exec($curl);
$projects = json_decode($response, true);
if (!$projects) {
echo 'No project to clone';
exit(1);
}
$projects = array_filter($projects, function($project) use ($namespace) {
return $project['namespace']['path'] === $namespace;
});
$projects = array_map(function($project) use ($namespace) {
return $project['ssh_url_to_repo'];
}, $projects);
echo implode("\n", $projects);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment