Skip to content

Instantly share code, notes, and snippets.

@reddragon
Created July 5, 2010 12:05
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 reddragon/464283 to your computer and use it in GitHub Desktop.
Save reddragon/464283 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# githubcommitinfo.rb - Fetches info about a commit on github.
# http://develop.github.com/p/commits.html
# Usage: $ ./githubcommitinfo.rb <gh_username> <gh_repo> <gh_branch>
# Dependencies:
# rubygems
# libcurl-devel (required to gem install curb)
# curb - gem install curb
# yaml
# Copyright (C) 2010 Gaurav Menghani <gaurav.menghani@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
require 'rubygems'
require 'curb'
require 'yaml'
github_username = ARGV[0]
github_repo = ARGV[1]
github_branch = ARGV[2]
if github_username.nil? or github_repo.nil? or github_branch.nil?
puts "Usage: $ ./githubcommitinfo.rb <gh_username> <gh_repo> <gh_branch>"
Process.exit(1)
end
curl_obj = Curl::Easy.http_post("http://github.com/api/v2/yaml/commits/list/#{github_username}/#{github_repo}/#{github_branch}")
yaml_obj = YAML::load(curl_obj.body_str)
if !yaml_obj[:error].nil?
puts yaml_obj[:error]
else
yaml_obj["commits"].each do |yo|
print "Message: ", yo["message"], "\n"
print "URL: ", yo["url"], "\n"
puts "Author: "
print "\tName: ", yo["author"]["name"], "\n"
print "\tEmail: ", yo["author"]["email"], "\n"
print "Id: ", yo["id"], "\n"
puts "Parents: "
yo["parents"].each do |parent|
print "\tid: ", parent["id"], "\n"
end
print "Committed Date: ", yo["committed_date"], "\n"
print "Authored Date: ", yo["authored_date"], "\n"
print "Tree: ", yo["tree"], "\n"
puts "Committer: "
print "\tName: ", yo["committer"]["name"], "\n"
print "\tEmail: ", yo["committer"]["email"], "\n"
puts ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment