I’ve been playing with the BitBucket API recently. It’s pretty neat - it’s a REST API that transmits data in JSON format. I can’t imagine a lower-friction way of getting at BitBucket’s data. It’s not complete, unfortunately, and does have some bugs, but hopefully it will improve over time.

My main reason for experimenting with it was to find a way of pulling down all Mercurial repositories belonging to a specific user. I’ve decided to take on curation duties for CaptainChemo’s repositories rather than leave them orphaned and unloved. I’m not sure what I’m going to do with them yet, though. There are a few private repositories in there that might contain proprietary code that I can’t open-source, but unfortunately I’m not in a position to find out.

Rather than use the command line to pull down the repositories one at a time, I knocked up a quick C# program to do it for me:

BitSync is command line driven. Example usage:

 bitsync /username ant512 /password mypassword
 /localpath C:\Mercurial /repoowner CaptainChemo

Note that the “repoowner” argument is case-sensitive.

BitSync will get a list of the repositories on the server and compare it with a list of repositories stored in the local destination path. If a repository already exists locally, BitSync will attempt to pull and update it. If a repository does not exist locally, BitSync will attempt to clone it.

Private repositories are only visible if the username and password combination have access to them.

The program uses a combination of Hammock and Json.NET for accessing the API, and my own PrettyConsole library developed in haste for the Woopsi font/bitmap tools.