Subverting Twitter

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: , , , , , , , , , ,

This entry was posted in learns_to. Bookmark the permalink.

0 Responses to Subverting Twitter

  1. dalas v says:

    your twitter page is a broken link.

  2. Greg says:

    Sure enough. I’ve fixed it now.

  3. winson says:

    Is there any means to send my svn commit message to twitter by subversion bundle with yours?

  4. @wilson: I’m not really sure I understand your question. Could you elaborate a bit?

  5. Aditya Sanghi says:

    Wouldnt it be cool if it works seamslessly off the svn hooks so we dont have to change the source control workflow? There could be people committing from various different OSes. It would reduce the overhead of having to install twitter etc on each system. I use Tortoise-SVN which is kinda cool for checking in on Windows and switch to cmdline when checking in from my ubuntu machine. Is there any such svn twitter post-commit hook you are aware of?

  6. @Aditya I think this would be more useful if implemented as a Subversion post-commit hook, yes. But that should be trivial to do. After all, any command you can run in the shell on the Subversion server you can easily also use in a hook script.
    Another challenge is to filter the content to be more suitable for short Twitter messages. A typical commit e-mail will contain a lot of information:
    http://blog.looplabel.net/2008/07/28/best-practices-for-version-control/#notifications

Leave a Reply

Your email address will not be published. Required fields are marked *