Integrating Launchpad and Gerrit Code Review

While talking about how Mahara uses Gerrit and Gitorious for code reviews, I forgot to include details on how to link bugs in the commit logs to our bug tracker (Launchpad).

Turning the bug numbers in git commit messages to links was just a matter of adding this to our etc/gerrit.config file.

[commentlink "launchpad"]  
  match = "([Bb]ug\\s+#?)(\\d+)"  
  link = https://bugs.launchpad.net/mahara/+bug/$2

All mentions of a bug number like "(bug #1234)" or "bug 5678" in a commit message or Gerrit review will be converted into links to the appropriate page on Launchpad.

Updating Launchpad bugs after Gerrit merges

Linking the original bug reports in Launchpad to committed code (and its review in Gerrit) was a little more complicated. It makes use of the hooks available in Gerrit.

The first step was to create a new Launchpad account for these automated updates and to confirm the email address it will be sending emails from. In our case, the account is MaharaBot.

Then, we wrote a custom hook script (inspired by one for JIRA) which we placed in ~/mahara_reviews/etc/gerrit.config.

For an example of what it sends to the bug tracker, see bug 788457.