Skip to content

Instantly share code, notes, and snippets.

@zkat
Last active September 3, 2015 22:04
Show Gist options
  • Select an option

  • Save zkat/217861 to your computer and use it in GitHub Desktop.

Select an option

Save zkat/217861 to your computer and use it in GitHub Desktop.
<?php
/**
* latest_github_commits.php
* Dumps a github commit report.
*/
/**
* Dump a report of the latest commits for a github repo.
*
* @param string $owner Account name that owns the repo in question.
* @param string $repo Project name of repository.
* @param string $branch Branch name to fetch latest commits from
* @param integer $num_commits Number of commits to dump (newest first)
*/
function latest_github_commits($owner, $repo, $branch, $num_commits) {
// For formatting niceness. I haven't set up a template engine.
$indent = " ";
$newline = "<br />\n";
// Grabbin' some JSON.
$url = "http://github.com/api/v2/json/commits/list/$owner/$repo/$branch";
$json = json_decode(file_get_contents($url), true);
// Dumpin' sum HTML! Wooooo....
echo "<ul>\n";
foreach ($json['commits'] as $key=>$value) {
if ($key >= $num_commits) { echo "</ul>"; return; }
echo " <li>\n" .
$indent . $value['message'] . $newline .
$indent . "Author: " . $value['author']['name'] . " " . $value['author']['email'] . $newline .
$indent . "Date: " . $value['committed_date'] . $newline .
$indent . "id: " . $value['id'] . $newline .
" </li>" . $newline;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment