Commit and merge hooks for Github and Lighthouse
April 30th, 2010
Github includes a service hook to allow commit messages containing Lighthouse ticket info trigger an update to the relevant tickets when you push changes. We use Lighthouse to keep track of bugs and feature requests, and were adding the ticket info to commit messages manually, but found ourselves both forgetting to do it, and making stupid typos. So, to make up for our incompetence, I automated the addition of ticket numbers and state to the commit messages using a couple of githooks…
Our code always goes to a staging environment for user acceptance testing (UAT) before being deployed to production. We settled on a custom state, coding-done, to indicate that coding has been completed, and committed, or merged, to our master branch, but has not yet been deployed to the staging server.
We also use topic/feature branches when working on anything substantial, and have started including a Lighthouse ticket number in the branch name, e.g. "LH007-permalink-from-lighthouse-ticket", and we always use the --no-ff option when merging to master, so we always generate a merge commit.
The hooks encourage use of the branch naming convention, and inclusion of a ticket number in commits directly to master (a number of formats are supported). They also set the state to coding-done.
It's quite likely that you don't follow our conventions, and don't intend to start doing so any time soon, but the code may still be a useful starting point. My starting point was Robby Russell's commit-msg hook.
My commit-msg hook looks for a Lighthouse ticket number in commits directly to master and both adds the new state, coding-done, and makes sure the ticket number is in a format that will be parsed by the Github service hook. For commits to topic/feature branches, it strongly encourages developers to stick with the branch naming convention.
The post-merge hook looks for the ticket number in the branch name, and then amends the most recent "merge branch" commit message to add the ticket number and state in the format expected by Github. This is kinda nasty, but I couldn't find a better way, and it does seem to work well.
To use the hooks as they are, save them as commit-msg and post-merge respectively and dump them into your .git/hooks directory. We actually added them to our repository and added symlinks from .git/hooks.
Sorry, comments are closed for this article.