Subverting Twitter

26 January, 2007

If it hasn't yet skittered across your radar, Twitter is a tiny web app that works a little like a universal IM away message. Created as a side project by Ev Williams and the gang at Odeo, Twitter lets you post tiny fragments of text (announcements of where you are and what you're doing, random thoughts and observations, etc.) via text message, IM, or the web. No more than 150 characters are allowed. It then broadcasts those messages to all of your friends and 'followers' and posts them to your own customizable page.

Here, for example, is my twitter page (warning: clicking may cause extreme boredom).

Anyway, it may be totally contrary to the spirit of such a pleasantly pointless thing, but I think I've found a use for Twitter that is actually…uh…useful: publishing commit messages from version-controlled coding projects.

Commit messages are the atomic unit of change in a project and can be the best way of keeping up with programming progress. Unfortunately, they all too often end up banished to obscure and unwieldy diff logs never to be regularly read. And worse, the knowledge of this sad fate leads harried coders to be lazy and uninformative in their composition making commit messages often doubly useless.

Maybe, publishing our commits to project-specific twitter pages, which our collaborators (and customers, and bosses) can follow in real time, will get us to give our messages some real zing as they become, not lost log entries, but comments in a conversation.

Or, at least, that's the theory, anyway. To test it out, I whipped up a solution for my current coding environment: a Rails project managed under Subversion. Specifically, I wrote a Rake task that prompts you for a commit message, runs the necessary svn commands to commit your code, and then forwards your commit message on to Twitter.

Well, more accurately, I extended Chris's svn tools plugin so that it uses addictedtonew's ruby twitter API library to post the message. Really, I did almost none of the work here, just tied together some real projects by others much more skilled than myself. Here's how you can do the same:

The first step is to get the svn tools plugin installed if you don't already have it. Chris mentioned today that he's thinking about refactoring it into a gem for use in Ruby projects more generally, but for now you can install it in your current Rails project like so:

> script/plugin install http://svn.rtra.in/public/plugins/svn_tools/

If you installed the plugin before January 26, 2007, you should reinstall it now, since Chris kindly made a little tweak to it to make my hack possible:

> script/plugin install http://svn.rtra.in/public/plugins/svn_tools/ --force

Once that's done, you're most of the way there. The next step is to install the twitter gem with hpricot upon which it depends:

> sudo gem install hpricot --source code.whytheluckystiff.net
> sudo gem install twitter

If you've already got the most avant-garde version of hpricot (today, it was 0.4.2), then you can skip the first of these two lines, but without it things will be quite bumpy.

Now, finally, all that's left is to add a new task to your project's own Rakefile. Anywhere in there (but not inside of a pre-existing namespace), add:

namespace :svn do
task :twitter => :commit do
email = 'me@mydomain.com'
password = 'mydogsname'
Twitter::Base.new(email, password).post(@message)
end
end

Obviously, this needs to get filled out with a valid twitter email address and password. And don't forget to stick "require 'twitter'" somewhere above this to make the gem accessible.

That's it, you're totally setup. Run it from your project's root directory with:

> rake svn:twitter

It will prompt you for the commit message, commit your code, and then send your message off to twitter, as promised.

You can see an example of this system in action by following the twitter page for the commits on grabb.it, a new semi-super-secret mfdz skunkworks project Chris and I are working on.

If you try it out, stop by and let me know how it works for you. Plus, if there's demand, I can always package this up as a gem once Chris does likewise with his svn tools, which would greatly simplify the install process and make it valid for non-Rails projects as well.

Ok, Twitter away!

Tagged: , , , , , , , , , ,