Skip to content

Instantly share code, notes, and snippets.

@schmunk42
Created April 11, 2013 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmunk42/5362844 to your computer and use it in GitHub Desktop.
Save schmunk42/5362844 to your computer and use it in GitHub Desktop.
create composer.json files from github API
<?php
class GithubApiParser
{
public $accessToken = "1234abcd";
public function __construct($model)
{
$this->_url = substr(str_replace("https://github.com/", "https://api.github.com/repos/", $model->url), 0, -4);
$this->_model = $model;
}
/**
*/
public function parse()
{
echo "Parsing " . $this->_url . "...\n";
$response = file_get_contents($this->_url . "?access_token=".$this->accessToken);
$repo = json_decode($response);
$response = file_get_contents($this->_url . '/tags?access_token='.$this->accessToken);
$tags = json_decode($response);
echo "Parsing master branch...\n";
$response = file_get_contents($this->_url . '/branches/master?access_token='.$this->accessToken);
$branch = json_decode($response);
$tags[] = $branch;
if (count($tags)) {
echo "Parsing tags...\n";
foreach ($tags AS $tag) {
#var_dump($tag);
$version = array(
'type' => 'package',
'package' => array(
'name' => $this->_model->owner . "/" . $this->_model->repository,
'description' => $repo->description,
'type' => $this->_model->type,
'homepage' => $repo->html_url,
'version' => $tag->name,
'source' => array(
'url' => $repo->clone_url,
'type' => 'git',
'reference' => $tag->commit->sha,
),
)
);
if (!strstr($tag->name, 'master')) {
$version['package']['dist'] = array(
'url' => $tag->zipball_url,
'type' => 'zip',
);
}
$versions[] = $version;
}
}
return $versions;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment