Pragmatism in the real world

Changing the GitHub IRC hooks notification events

As joind.in uses GitHub to host its source code, we use the IRC hook to receive notifications to the IRC channel (#joind.in on freenode) when interesting things happen on the GitHub repositories.

We noticed recently that we were being notified about more types of things happening on some repositories compared to others, so I decided to investigate.

The code for this is here and a quick perusal of it shows that it will do something for these events:

  • push
  • commit_comment
  • pull_request
  • pull_request_review_comment
  • issues
  • issue_comment

However, when you go the administration page on the website, you cannot set which events to be notified on.

Fortunately, GitHub has an API and so you can quite easily manipulate the hooks using curl.

To read all the hooks attached to a project, you do this:

curl -u '{your github username}' -H "Accept: application/json" 
https://api.github.com/repos/{owner name}/{repository name}/hooks

so, for the joind.in API project, I do:

curl -u 'akrabat' -H "Accept: application/json" 
https://api.github.com/repos/joindin/joindin-api/hooks

This will return a list of hooks attached, including all the information about them. In this case, I’m interested in the IRC hook and there’s two interesting keys in the results:

    "url": "https://api.github.com/repos/joindin/joindin-api/hooks/932001",
    "events": [
      "push",
      "pull_request"
    ],

The url provides the information on the end point to use to change the data and the events tell me what’s set up. As you can see, only “push” and “pull_request” are set up for this repository.

To change this, we simply use CURL to POST a new set of events:

curl -u 'akrabat'  -H "Accept: application/json" -H "Content-type: application/json" -X PATCH 
https://api.github.com/repos/joindin/joindin-api/hooks/932001 
-d '{"events":["push", "pull_request", "commit_comment", "pull_request_review_comment"]}'

Helpfully, the response includes a representation of the hook we have just modified, so we can see that the events list has changed. For more information, look at GitHub’s API documentation for hooks.

I therefore went through all the joind.in repositories and set them all to the same set of events for consistency. We’ll no doubt find out soon if that results in too many notifications to the channel!