Skip to content

Instantly share code, notes, and snippets.

Last active November 2, 2020 17:32
What would you like to do?
Probot plugin that ensures every commit message has the word "bananas"
# The ID of your GitHub App
# Uncomment this to get verbose logging
# LOG_LEVEL=trace # or `info` to show less
# Go to set this to the URL that you are redirected to.

Build a bot!

This guide will walk you through running a simple GitHub App that ensures every commit has the word bananas and get it running on a test repository. All of the source code you need is in this gist.

Here's what it will look like when your commits are not bananas:

…and here's what it will look like when your commits are bananas:

Ready? Let's get started!

  1. Clone this gist

     $ git clone bananas
  2. Make sure you have a recent version of Node.js installed.

     $ node --version
  3. package.json lists the dependencies for our app. Check it out, and then run:

     $ npm install
  4. index.js is the meat of the app. Read through the code and see if you can make sense of what it's doing.

  5. Go to and click Start a new channel. Set WEBHOOK_PROXY_URL in your .env to the URL that you are redirected to.

  6. Create a new GitHub App with:

    • GitHub App name: yourusername-bananas, replacing yourusername with your GitHub username.
    • Homepage URL and User authorization callback URL: It doesn't matter for this tutorial, so set to, replacing yourusername with your GitHub username.
    • Webhook URL: Use your WEBHOOK_PROXY_URL from the previous step.
    • Webhook Secret: development
    • Permissions:
      • Commit statuses: Read & Write
      • Pull requests: Read-only
    • Subscribe to events
      • Pull request
    • Click Create GitHub App
  7. Most importantly, your bot needs an adorable icon. Feel free to use bananas.jpg.

  8. Generate a private key and move it to the project directory.

  9. Edit .env and set APP_ID to the ID of the app you just created, and SUBDOMAIN to your GitHub username.

  10. Click the Install button on your app page, and install it on a repository.

  11. Go back to your terminal and run $ npm start to start the server, which will output Listening on http://localhost:3000.

  12. Now go to your repository and create a new file, commit it to a branch, and open a pull request.

Want to learn more:

// A plugin is a Node module that exports a function which takes a `robot` argument
module.exports = robot => {
// Listen for a pull request being opened or synchronized
robot.on('pull_request', async context => {
// Just assign a variable to make our life easier
const pr = context.payload.pull_request;
// Get all the commits in the pull request
const compare = await context.github.repos.compareCommits(context.repo({
base: pr.base.sha,
head: pr.head.sha
// Check that every commit has the word "bananas" in it
const isBananas = => {
return data.commit.message.match(/bananas/i);
// Parameters for the status API
const params = {
sha: pr.head.sha,
context: 'bananas',
state: isBananas ? 'success' : 'failure',
description: `Your commits ${isBananas ? 'are' : 'need more'} bananas`
// Create the status
return context.github.repos.createStatus(context.repo(params));
"private": true,
"scripts": {
"start": "probot run ./index.js"
"dependencies": {
"probot": "^5.0.0"
"devDependencies": {
"smee-client": "^1.0.1"
"engines": {
"node": ">= 7.7.0",
"npm": ">= 4.0.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment