Skip to content

Instantly share code, notes, and snippets.

@schmunk42
Created October 8, 2012 16:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmunk42/3853414 to your computer and use it in GitHub Desktop.
Save schmunk42/3853414 to your computer and use it in GitHub Desktop.
Test-script to auto-generate packages.json from github API
<?php
// get all repos from yiiext
$response = file_get_contents("https://api.github.com/orgs/yiiext/repos");
$repos = json_decode($response);
#var_dump($repos);
// get versions/tags
$satis = array();
foreach($repos AS $num => $repo) {
if ($num > 5) break; // TODO - just for debugging
$response = file_get_contents($repo->url.'/tags');
$tags = json_decode($response);
#echo "REPO:";
#var_dump($repo);
#echo "TAGS:";
#var_dump($tags);
foreach($tags AS $tag){
$versions[$tag->name] = array(
'name' => $repo->full_name,
'description' => $repo->description,
'version' => $tag->name,
'source' => array(
'url' => $repo->clone_url,
'type' => 'git',
'reference' => $tag->commit->sha,
),
'dist' => array(
'url' => $tag->zipball_url,
'type' => 'zip',
),
);
$packages[$repo->full_name] = $versions;
}
};
$satis = new StdClass();
$satis->packages = $packages;
$json = json_encode($satis);
file_put_contents ("packages.json" , $json);
echo "packages.json generated.";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment