Skip to content

Instantly share code, notes, and snippets.

@lennartkoopmann
Created January 28, 2009 21:22
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 lennartkoopmann/54199 to your computer and use it in GitHub Desktop.
Save lennartkoopmann/54199 to your computer and use it in GitHub Desktop.
Fetch your last commit using the GitHub API and Ruby/Rails
helper_method :get_last_commit
def get_last_commit
require "cobravsmongoose"
require "open-uri"
require "timeout"
retries = 1
response = "";
begin
Timeout::timeout(2){
response = open("http://github.com/api/v1/xml/lennartkoopmann/scopeport-server/commits/master").read
}
rescue Timeout::Error
retries -= 1
if retries > 0
sleep 0.42 and retry
else
return "Could not fetch commits"
end
end
commits = CobraVsMongoose.xml_to_hash(response)
author_name = commits["commits"]["commit"][0]["author"]["name"]["$"]
message = commits["commits"]["commit"][0]["message"]["$"]
url = commits["commits"]["commit"][0]["url"]["$"]
date = commits["commits"]["commit"][0]["committed-date"]["$"]
return "\"#{message}\" at #{date} by #{author_name} - <a href=\"#{url}\">more information</a>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment