DEV Community

Cover image for Build a GitHub App in 5 Minutes with Probot
Jaison D Souza
Jaison D Souza

Posted on

Build a GitHub App in 5 Minutes with Probot

Build a GitHub App in 5 Minutes with Probot

In this article I will show you how to build your own GitHub app in 5 minutes. You can put this in your portfolio, show a friend or just do it for fun. Without any further ado, let’s begin.

Prerequisites

  • ANY code editor.
  • Node.js installed.
  • Little bit of programming knowledge. Just a little.
  • Oh, and a GitHub account.

Step 1: Setup the project

Open a code editor. I will use VS Code. Then open a terminal.

Run this command:

npx create-probot-app app_name
Enter fullscreen mode Exit fullscreen mode


`

Enter the name, description, and your name. Then it will ask you to choose a template.

If you’re using JavaScript, select basic-js; for TypeScript, choose basic-ts — which is what I'll use in this example.

There are also some built-in templates like checks, deploy, and git-data, which you can explore if you'd like.

Step 2: Initialize your Smee client

Visit https://smee.io/new to generate a channel and copy the URL.

Open terminal and run the following command:

bash
npm install --global smee-client

Then open .env.example file and rename it to .env.

Paste the URL from Smee in front of WEBHOOK_PROXY_URL.


You might be wondering what to paste in APP_ID?
We will do that in the next step.

Step 3: Initialize GitHub App

Go to: https://github.com/settings/apps/new

Fill out the name, description, and homepage URL of your app. If you don’t have a homepage URL, just give your GitHub page.

  • Webhook URL: Use the same WEBHOOK_PROXY_URL from the previous step.
  • Webhook Secret: Use whatever you set in your .env file.
  • Permissions: Choose permissions required for your app. If unsure, use checks, contents, issues, push, and pull requests. You can change them later.

Click on Create GitHub App. You will be redirected.

Copy the App ID and paste it into your .env.

Scroll down to the Private Keys section.

Click on Generate a Private Key.


A .pem file will be downloaded. Copy the file into your project folder.

Rename it to github_key.pem.

Remember to add github_key.pem and .env files to .gitignore.

Paste this into the .env file:

env
PRIVATE_KEY_PATH="./github_key.pem"

Then in terminal, open your app folder and run:

bash
cd app_name
npm start

Final Step: Add a Simple Feature

You have successfully created your GitHub App. You can now modify the code to respond to events like push, pull_request, or issues.

Here’s an example that comments "thank you for raising the issue!" on every new issue:

`ts
import { Probot } from "probot";

export default (app: Probot) => {
app.on("issues.opened", async (context) => {
const issueComment = context.issue({
body: "thank you for raising the issue!",
});
await context.octokit.issues.createComment(issueComment);
});
};
`

That’s how you build your own GitHub App with Probot — quick and easy!

Check It Out

I used this same method to build Codexa — a GitHub Copilot-like tool for reviewing pull requests.
Feel free to check out the code and see how it works.

Code: github.com/jsndz/blogs/tree/master/tutorial
Wanna connect? Reach out on LinkedIn
Also, check out more of my projects on GitHub

Top comments (0)