Redmine plugin: Github Hook

I use Redmine to keep track of most of Substance Labs projects. It’s a nifty, open source project management/issue tracking system, and I am quite happy with it.

I also use Git for most my source control management needs, and I tend to push my repositories to Github when I need to share them with others.

If you too fit this description, I have a little treat for you; a Redmine plugin that makes Github integration easy.

Redmine and Github in the old days

Redmine has built-in support for Git repositories, allowing you to browse your code and view your changesets directly in Redmine. For this purpose, it relies on local clones of the Git repositories.

If your shared repository is on a remote machine – for example on Github – this unfortunately means a bit of legwork to keep the local, Redmine-accessible repository up-to-date. The common approach is to set up a cronjob that pulls in any changes with regular intervals and updates Redmine with them.

Redmine and Github in the future

The cronjob approach works perfectly fine, but is a bit heavy-handed and cumbersome for my taste. So I created the Github Hook plugin for Redmine, which allows your Redmine installation to be notified when changes have been pushed to a Github repository.

Installation

  1. Installing the plugin
    1. Install the json gem <http://json.rubyforge.org/> on the machine where Redmine is running.
    2. Install the plugin from http://github.com/koppen/redmine_github_hook by following the standard plugin installation procedure.
    3. Restart your Redmine.
    4. If you already have a local Git repository set up and working from Redmine go to step 3, otherwise continue at step 2.
  2. Adding a Git repository to a project (note, this should work whether you want to use Redmine Github Hook or not)
    1. Go to the directory on your Redmine machine where you want to keep your repository, for example /home/redmine/repositories/.
    2. Get a clone of the repository into that location: git clone git://github.com/koppen/redmine_github_hook.git. This creates a .git directory at /home/redmine/repositories/redmine_github_hook/.git
    3. Open Redmine in your browser and navigate to the Settings for the project you want to add a Git repository to.
    4. Under the Repository tab, choose Git as your SCM and enter the full path to the .git directory from step 2; /home/redmine/repositories/redmine_github_hook/.git . Click “Create”.
    5. Click the new “Repository” link in the main navigation to verify that your repository integration works.
  3. Connecting Github to Redmine
    1. Go to the repository Admin interface on Github.
    2. Under “Service Hooks” add a new “Post-Receive URL” of the format: “[redmine_installation_url]/github_hook” (for example “http://example.com/github_hook”).

That’s it. Using the magic of Post-Receive Hooks" Github will now send a HTTP POST to the Redmine Github Hook plugin whenever changes are pushed to Github. The plugin then takes care of pulling the changes to the local repository and updating the Redmine database with them.

You can grab the plugin at http://github.com/koppen/redmine_github_hook/