Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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