Created
December 28, 2020 18:05
-
-
Save g105b/eeb375061560aa67deb611617f46642d to your computer and use it in GitHub Desktop.
Git clone and composer install all repositories from a Github organisation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 [email protected]:$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