Created
April 11, 2013 12:03
-
-
Save schmunk42/5362844 to your computer and use it in GitHub Desktop.
create composer.json files from github API
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 | |
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