Skip to content

Instantly share code, notes, and snippets.

@g105b
Created December 28, 2020 18:05
Show Gist options
  • Save g105b/eeb375061560aa67deb611617f46642d to your computer and use it in GitHub Desktop.
Save g105b/eeb375061560aa67deb611617f46642d to your computer and use it in GitHub Desktop.
Git clone and composer install all repositories from a Github organisation
<?php
if(count($argv) <= 1) {
echo "Usage: getall.php OrganisationName [PathToParentDir]", PHP_EOL;
exit(1);
}
$org = $argv[1];
$path = $argv[2] ?? getcwd();
$path = realpath($path);
chdir($path);
$ch = curl_init("https://api.github.com/orgs/$org/repos");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Greg's Github downloady thing");
$response = curl_exec($ch);
$json = json_decode($response);
if(!$json) {
echo "There was an error!", PHP_EOL;
var_dump($response);
exit(1);
}
foreach($json as $repo) {
$name = $repo->name;
$cmd = "git clone git@github.com:$org/$name";
echo $cmd, PHP_EOL;
`$cmd`;
$cmd = "cd $name && composer install && cd ..";
echo $cmd, PHP_EOL;
`$cmd`;
}
echo "DONE!", PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment