This was taken directly from mozbase, I'm sure we could tweak it to our needs.