I am actively working on PoolParty, but the website doesn’t necessarily show that the project is in active development.
Luckily, it is hosted at github and they have an API to access their changesets. Now, on PoolParty’s website, I am surfacing the latest changeset’s time, message and author as well as a link to the changeset.
How?
Code (shortened for brevity purposes):
$:.unshift(File.dirname(__FILE__))
require "rubygems"
require "yaml"
require "open-uri"
class Grab
@url = "http://github.com/api/v1/yaml/auser/pool-party/commits/master"
@refresh_after = 20
def self.latest_commit_object
o = yaml["commits"][0]
{
:message => o["message"].gsub(/\n/, ""),
:date => Time.parse(o["committed_date"]).timeago,
:by => o["committer"]["name"],
:url => o["url"]
}
end
end
The github api is slick. As you can see from above, the format for the api url looks like
http://github.com/api/version/format/username/repository/type/object
Where the variables there correspond to:
- Current version: v1
- Acceptable formats: json, xml, yaml
- Acceptable types: commits, commit
Grabbing the latest changesets from the url as YAML format, we can quickly and easily parse the message into a useful hash.
I personally like the “# hours ago” syntax that 2.0 sites are popping up with everywhere, so I just added a timeago method that is very similar to the one included with rails. The source is attached.
Since I don’t want poolpartyrb.com’s load time to be dependent upon how fast it can hit github, I cache the variable so every 20 views it refreshes.
Use in Rails
Save both the files (attached below) to your lib directory.
Add this to your environment.rb
require 'grab'
Then add this helper to your application_helper.rb
def show_latest_commit
@latest_commit = Grab.latest_commit_object
<<-EOS
Latest commit
#{@latest_commit[:message]}
by #{@latest_commit[:by]}
#{@latest_commit[:date]}
EOS
end
How to use in sinatra
I use this on poolpartyrb.com, which is a sinatra site. I do basically the same as above, but generally render the code in haml instead
$:.unshift(File.dirname(__FILE__))
require "sinatra"
require 'grab'
get '/' do
@latest_commit = Grab.latest_commit_object
haml :home, :layout => :layout
end
Then in my home.haml
.note
%strong
Latest commit
%br
==
= @latest_commit[:message]
.highlight
== by #{@latest_commit[:by]}
= @latest_commit[:date]
edit: updated location of code

{ 2 comments… read them below or add one }
Greetings, Cool idea…
I do the same thing with an svn repository on the forum for an open source app I develop.
The top level forum page does an asynchronous call and fills in the data when the response comes back, so it doesn’t stop the basic page load, but the information is always fresh. It can take up to around a half second for the changeset information to show up, but most people don’t notice.
{ :controller => ‘feeds’, :action => ‘index’ }, :update => ‘changes’} -%>
//<![CDATA[
Event.observe(window, "load", function() {});
//]>
It seems that pool party is down. :(