Created
January 28, 2009 21:22
-
-
Save lennartkoopmann/54199 to your computer and use it in GitHub Desktop.
Fetch your last commit using the GitHub API and Ruby/Rails
This file contains hidden or 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
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