Build a Github Application

Jida Asare
3 min readMar 7, 2021

--

image src: https://www.searchenginejournal.com/google-analytics-filters-bot-traffic-from-app-web-properties/373387/

Github applications can be built to extend GitHub functionalities. You can create a GitHub application to automate workflows. Certain functionalities for which one can build a Github application include: creating an issue, commenting on issues or discussions, merging pull requests if it meets the criteria of a protected branch, etc.
Github applications are different from Github OAuth applications.
Github applications are first-class actors. They can exist as actual entities which can perform actions that actual users or organizations can. Unlike Github OAuth applications that can only perform actions on behalf of users.

Github applications have distinct granular permissions and can be set up to respond to webhook events from Github actions by a user or an organization.

In this article, we are going to set up a Github application that listens to push events on the master branch of a Github repository. We will be using the Probot Framework to create the Github application.

Probot Framework is a Nodejs Framework for creating Github applications. It makes the creation of a Github application relatively easy and maintains focus on building the functionality of the application whiles Probot handles other responsibilities like receiving and validating webhooks. View more information on the Probot documentation here.

Creating a Github application

To create a Github application first install probot with this command in the command-line interface(CLI) :
npx create-probot-app unblock-me

This command creates scaffolds a probot app called unblock-me. Follow the CLI prompts and answer the questions in the CLIto successfully complete the probot app.

To successfully run the application, run the following commands in the terminal:

cd unblock-me
npm start

Set Up the Github Application

To setup the Github application, in the browser navigate to
http://localhost:3000/

View welcome to unblock-me in the browser

Click on Register Github app. This will navigate you to a URL to create a new Github application. Provide the app name eg. unblock-me

Complete creation of the Github application. You will be redirected to install the application on a test repository.

Test the application by triggering a webhook. Create a sample issue on the application. Then navigate to: https://github.com/settings/apps/<app-name>/advanced to view webhooks triggered.
Webhooks should be triggered successfully.

Responding to Webhooks in the Project

In the index.js file, we will listen to webhooks events. First, update the application permissions to listen to push events in the Github test repository here:
https://github.com/settings/apps/<app-name>/permissions

Now include the code below in the index.js

listen to webhook push event on Github

The code above listens to the Github push event on the test repository and logs the information on the event. In the Index.js file, we can subsequently respond to the push event that was triggered in the repository. To view other webhook events that can be listened to and responded to view the webhook events here.

--

--