GitHub: An open source app for pull request review

Gotcha: A golang bot that helps automate basic engineering tasks.

D2Relz
3 min readDec 25, 2021

Event-driven architecture is increasingly discussed and used in environments that need large scale and are implemented in a granular way. In a way, it’s a great cordless phone that forwards messages, and each receiver does a piece of the work. In short, good teamwork with well-defined scopes.

Unfortunately, this conversation is not about that! Well, not completely.

Introduction

An GitHub app allows listening to events through a webhook and creating actions based on the desired business logic. An event can be any interaction with Github, from creating a repository to a simple comment. We can imagine a scenario where a pull request is opened, consequently an event is fired for the app and then it performs a lint check in the code. In the case of a failure, an automatic response happens telling you what can be done to correct it and where to find the failure.

In an environment where there are multiple teams or even in an open source repository, an app with basic and necessary functionality can make the engineer’s life easier and increase the team’s productivity.

Thus, the purpose of this article is to play with golang, implementing an open source app for GitHub, called Gotcha.

Hands On

All information needed to run the bot, as well as documentation, are found in the github repository.

First, I created a yaml file with all possible bot settings, from information from GitHub itself (appId, webhookSecret, privateKey, events…) to custom commands with the features.

The first section of yaml (administration) is responsible for setting user permissions on some bot commands. The most interesting part, pullRequest is actually a summary of what the bot can do so far.

  • approveCommand: Command for approval of the PR by Gotcha.
  • runTestSuiteCommand: Command to re-run the test suite.
  • mergeCommand: Command for merge of the PR by Gotcha.
  • mergeAndDeleteCommand: Command for merge and delete ref branch of the PR by Gotcha.
  • namePattern: Format (regex) that pull request name must follow.
  • reviewers: The pull request needs reviewers.
  • assignees: The pull request needs assignees.
  • labels: The pull request needs labels.

According to the settings entered in the github section of yaml, authentication with GitHub is done as per the following code.

As an example, here is a piece of code on how Gotcha runs test cases when a pull request is opened.

Final Remarks

Despite simple features, the need to drive them in every collaborative environment is quite necessary. Thus, a bot-driven automation serves both to maintain quality, organize and streamline maintainer tasks.
The summary presented here was just a demonstration of what we can do, in the repository you can find the complete code, as well as install it in your own repository.

It’s worth noting that this is an early stage project, I hope to implement more features and if anyone is interested, the doors are open for contributions or suggestions!

https://github.com/diegolnasc/gotcha

--

--