In our previous article, we looked at how to get started using GitHub webhooks.
However, what are the actual real-world applications of GitHub webhooks? In what ways can this technology deliver value to our applications? These are the questions we will be trying to provide answers to in this article by taking a look at some of the most common real-world applications of GitHub webhooks.
Why are GitHub webhooks important/useful?
Before we dive into the various use cases of GitHub webhooks, let's discuss why GitHub webhooks are a useful piece of technology. For over a decade now, GitHub has served as a central hub for storing, sharing, and collaborating on code-based projects.
It can be argued that GitHub houses the code for most of the software applications, frameworks, plugins, and any code-based technology that we use today. Thus, it is important that such a platform should open doors to integrations with other external systems that rely on the code hosted on it.
GitHub webhooks provides one such integration opportunity by allowing external applications to subscribe for events taking place on GitHub. These external applications can then receive notifications and information about their subscribed events, and trigger workflows in response to these events. This way, subscribed applications can deliver more value to their users (especially through the automation of tasks). The beauty of GitHub webhooks is that they are not restricted to any use case; you are only limited by your own imagination.
In the following sections, we will take a look at some of the most common scenarios in which application engineers have employed the use of GitHub webhooks to give you an idea of the flexibility that is possible.
Triggering continuous integration build pipelines
One of the most common applications of GitHub webhooks is the triggering of continuous integration pipelines to run tests on code being pushed to a branch. Team members working on a project send pull requests from feature branches to the main branch. Before these feature branches are merged to the main branch, it's considered best practice to run the code to be merged through tests.
You can set up a continuous integration (CI) pipeline on a CI server (Jenkins, CircleCI, etc.). Then subscribe for
pull_request events on GitHub to fire webhooks to trigger your CI server to run tests on the branch.
This will prevent defective code from being merged to your main branch when errors are detected in the CI build and the build fails.
Automatically deploying applications to destination servers
For web projects, it is important for development teams to deliver their code to application servers where users and/or testers can access it. Whether you need to deliver your web app to a staging or production environment, a continuous delivery pipeline can be set up to move your code to the hosting environment.
However, this deployment pipeline needs a trigger to tell it when to ship your code to the host. Developers can simply subscribe for a
push event on the main branch (for deployment to production servers), or any deployment branch. When the
push event occurs, a webhook is sent to trigger the deployment pipeline to ship the code to the hosting environment.
CI/CD platforms like CircleCI have API endpoints to trigger a deployment pipeline. You can simply point your webhook to this endpoint to trigger a deployment to your servers.
Sending notifications to team collaboration channels like Slack and Discord
GitHub tries its best to send email notifications for commits and pull requests on repositories. However, development teams spend most of their time on collaboration platforms like Slack and Discord.
Thus, the most effective way to communicate activities happening on code repositories to team members, especially code reviewers and deployment approvers, is via these collaboration channels. This ensures that anyone who needs to take immediate action gets the notification on time. This can also help facilitate discussion on commits and issues, which allows the team to stay in sync with activities taking place on the repository.
Discord allows developers to generate a webhook endpoint URL that can be submitted to GitHub when subscribing to a webhook. This allows you to get instant notifications on subscribed events in your Discord channels. You can follow this GitHub gist to see how GitHub webhooks can be used to channel event details to Discord channels.
When subscribing for webhooks to be sent to discussion channels, you can subscribe to as many events as you're interested in. There are no rules as to what you should have sent to you.
Updating external issue trackers
GitHub includes an Issues tab on each repository where users of the application and code collaborators can submit issues observed. Discussion threads can then be created on each issue to share information about resolving the issue.
However, some external applications do a better job at handling issues than GitHub. These issue trackers often possess more features for dealing with code issues and helping developers collaborate better on a project.
Some of these issue trackers, like Jira, have built-in support for GitHub to follow up on issues on a repository. Others, like Pivotal Tracker and MongoDB Realm, provide you with a webhook URL that you can add to GitHub to subscribe to the issues events, issue comment event, commit comment event, and any other event related to issues tracking.
Automating workflows on external processes
Another interesting use of GitHub webhooks is in triggering workflows on external applications and processes. This use case is custom, and always dependent on what the application engineer wants to achieve.
It can be as simple as logging activities taking place on GitHub for audit purposes, or triggering database servers to backup data before a release is made. Project management applications can subscribe to events like
pull_request to keep track of the project.
Customer support applications can subscribe to the
issues event to collate complaints, comments, and issues that users are reporting on GitHub.
If there is a process you need to automate in your custom application, database servers, SaaS applications, or email servers in response to any activity on GitHub, you can achieve this automation with GitHub webhooks.
The simplicity of GitHub makes it easy to integrate into a wide range of external applications and processes. Almost every application supports HTTP, and since webhook requests are simple HTTP requests carrying a payload of event information, they can easily communicate with a lot of online applications. In this article, we have looked at some of the common scenarios where GitHub webhooks are deployed.
GitHub webhooks use cases are not limited to what we have seen in this article, but having these examples at hand will help you better understand how to use GitHub webhooks to their full potential.
If you are interested in building an integration with GitHub webhooks, we recommend reading our tutorial for GitHub webhooks to kick start your project!
Top comments (0)