Over a million developers have joined DZone.

Changing the GitHub IRC Hooks Notification Events

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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 about.

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}/hookscurl -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!



The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:

Published at DZone with permission of Rob Allen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}