Automate GitHub Issues status of your organization with Webhooks
Introduction
Let’s suppose you are holding an organization which builds products and develop them, you are gonna use GitHub repositories(public/private) to keep all your code or resources safe and secure without getting messed up. In the time, you will be using an amazing feature of GitHub repos to raise an Issue and look forward to someone in or out of the organization to solve it!
For now, your issue status is open
As the issue is open, you wanted to get updated to your database if it’s got commented or solved by someone. For this, the old traditional approach to keep requesting the Github server for status updates and then updating in your database alongside, which is not an effective approach and here comes the helping hand of Github feature ‘WebHooks’ which make the process easier
WebHooks
WebHooks is an amazing external service in which the server reach you out with a POST request automatically when certain events happen, rather continuously requesting the server for any changes. Learn more at Webhooks Guide.
How do WebHooks works?
How to create a GitHub Webhook
First and for most, Webhooks can only be created for an organization that you are holding.
Go to the settings page of your organization and look for the option Webhooks
The above image may change for times, but the configuration should be similar.
Payload URL
The URL you provide will be get triggered when particular events(you could choose the required events in the third option ‘which Events would you like to trigger this webhook?’)happen
Payload URL should consist a service that should receive data(payload) from GitHub. Follow up my next writings to learn how to write a service and deploy to Heroku that receives data.
Content-type
The Content-type is a header, which is used to indicate the media type of the response. As GitHub Webhook sends the response in JSON format, we are gonna select ‘application/json’ Learn more at MDN-ContentType
Secret
As you configure the payload link and content-type, here’s the security part to secure your service that receives data. This ‘secret’ part is to limit the requests to those coming from GitHub, there are a couple of ways to do this. But, for simplicity, I’ll be leaving it blank for now. Learn more about this at Securing your WebHook.
which Events would you like to trigger this webhook?
As it sounds, this option helps you to subscribe for particular events, In which the Payload URL should get triggered,
We are gonna select “Let me select Individual Events”
You can choose your required Events, for getting issue status and issue comments we choose “Issue Comments” and “Issues”
Click on Add webhook. you are ready to go!
To know the Recent Deliveries of Webhook, go back to your webhook page and select the existing WebHook and scroll all the way to down find Recent Deliveries
Originally Published at: FnPlus Tech Blog