Skip to content

Instantly share code, notes, and snippets.

@jesusr
Last active August 29, 2015 14:10
Show Gist options
  • Save jesusr/093dfd21cdb080c117fc to your computer and use it in GitHub Desktop.
Save jesusr/093dfd21cdb080c117fc to your computer and use it in GitHub Desktop.
Github Extract Commit, Contributors and Issues data with PHP, the awful way
<?php
function getGithubData($user,$repo){
$ch = curl_init();
$url = 'https://api.github.com/repos/'.$user.'/'.$repo.'/commits';
$url2 = 'https://api.github.com/repos/'.$user.'/'.$repo.'/stats/contributors';
$url3 = 'https://api.github.com/repos/'.$user.'/'.$repo.'/issues';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Awesome-Octocat-App'));
$head = curl_exec($ch);
$data['commits']= sizeof(json_decode($head));
curl_setopt($ch, CURLOPT_URL, $url2);
$head = curl_exec($ch);
$data['contributors'] = sizeof(json_decode($head));
curl_setopt($ch, CURLOPT_URL, $url3);
$head = curl_exec($ch);
$data['issues'] = sizeof(json_decode($head));
return $data;
curl_close($ch);
};
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment